BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Bal23
Lapis Lazuli | Level 10
%LET id1= a2222;
%let id2=b1222;


%macro wins(N) ;
DATA lib1.&id1. ;
set
  %do I= 1122 %To &N;
%if %sysfunc(exist(lib2. a&i)) 
%then %str( lib2. b_c_201&i ) ;
%end;
;
where	id2 ="&id2"

	
;


%mend wins; 
%wins(3322 );

 I have used this quite well but my current task is that id2 has three values instead of one. My question is, should I remove this macro, and type each value instead, such as: where id2 in ("1233","1234","1245")

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

You could use:

%let id2='James','Jane','John';
data want;
  set sashelp.class (where=(name in (&id2.)));
run;

Art, CEO, AnalystFinder.com

View solution in original post

3 REPLIES 3
art297
Opal | Level 21

You could use:

%let id2='James','Jane','John';
data want;
  set sashelp.class (where=(name in (&id2.)));
run;

Art, CEO, AnalystFinder.com

PaigeMiller
Diamond | Level 26

To expand on the correct answer by @art297, don't mix the data which can be variable (the values that &id2 takes on) with the data step code which is constant.

 

If the only thing that is varying is

 

"1233","1234","1245"

 

so that's all you need to include in the macro variable. The part which reads

 

where id2 in

 

is constant so it should not be put into a macro variable.

--
Paige Miller
Astounding
PROC Star

You are already working in a macro, so you can use a %DO loop.

 

As long as the values inside the IN operator are consecutive, you can use this construct to get your WHERE statement:

 

where id2 in (   %do i=&id2 %to &id2 + 2;    "&i"  %end;  ) ;

 

The pieces in red become your WHERE statement.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 802 views
  • 2 likes
  • 4 in conversation