%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")
You could use:
%let id2='James','Jane','John'; data want; set sashelp.class (where=(name in (&id2.))); run;
Art, CEO, AnalystFinder.com
You could use:
%let id2='James','Jane','John'; data want; set sashelp.class (where=(name in (&id2.))); run;
Art, CEO, AnalystFinder.com
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.
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.