Hello Guys,
need your help in macro.
below is my code.
%let a1=1;
%let a2=2;
%let a3=3;
%let a4=4;
%let a5=5;
%let a6=;
%let a7=;
%let a8=;
%let a9=;
%let a10=;
%macro export;
%do i = 1 %to &nod;
%let nm&i = &&nm&i;
proc sort data = db.&&nm&i out = &&nm&i;
by &subject;
run;
data db1.&&nm&i;
set &&nm&i;
by &subject;
where &subject in (&a1,&a2,&a3,&a4,&a5); ***************provide subject/patient number for output data set***********************;
run;
%end;
%mend export;
%export;
now i want the result on the base of my macroparameters means if i fillup 5 macro para then in my where condition it should took only 5 variables and if i fill up 10 then it should take 10 values.i have highlited the part.
is it possible ? kindly guide me.
Thanks,
Chirayu
hi,
i am still have some questions ...
what are the values you assinged to the following ?
&nod...........?
&subject...........?
And please try without macros for single value/excution......and post here...some one would help you
Regards
ALLU
Thanks for replaying,
i just want to know how we can use all global macros in where condition with IN operator ? Means if i use 5 macro value then no need to update where condition,my where condition should be remain same. Is it possible ?
You can reference the empty macro variables in your where condition. For example run these simple test cases.
%let a1=14;
%let a2=;
%let subject=age ;
data want ;
set sashelp.class ;
where &subject in (&a1,&a2);
run;
%let a1='Alfred';
%let a2=;
%let subject=name ;
data want ;
set sashelp.class ;
where &subject in (&a1,&a2);
run;
I believe below sample covers what you're asking for.
%let a1=1;
%let a2=2;
%let a3=3;
%let a4=4;
%let a5=5;
%let a6=;
%let a7=;
%let a8=8;
%let a9=;
%let a10=;
proc sql noprint;
select value into :in_values separated by ','
from dictionary.macros
where scope='GLOBAL' and prxmatch('/A\d+/oi',name)=1 and not missing(value)
;
quit;
data test;
do i= 0 to 10;
if i in (&in_values) then output;
end;
run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.