%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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.