In this example what is the purpose of comma (",age,") in the concatenation function (cats).
%macro mymacro(age=0);
proc sql noprint;
select quote(name) into :namelist separated by ','
from sashelp.class where age=&age.;
quit;
data name_age;
set sashelp.class;
where name in (&namelist.);
run;
proc print data=name_age;
var name age;
run;
%mend mymacro;
proc sort data=sashelp.class out=class nodupkey;
by age;
run;
data _null_;
set class;
exec_val = cats('%mymacro(age=',age,')');
call execute(exec_val);
run;
The comma separates the values that are to be concatenated. In this case the values are:
'%mymacro(age=
The value of the variable age
')'
to make a string that could be
%mymacro(age=23)
as the call to the macro when the data _null_ step terminates.
The comma separates the values that are to be concatenated. In this case the values are:
'%mymacro(age=
The value of the variable age
')'
to make a string that could be
%mymacro(age=23)
as the call to the macro when the data _null_ step terminates.
Out of interest, why all the code? It basically distills down to:
proc sort data=sashelp.class out=class; by age; run; proc print data=class; by age; run;
Or worse case scenario:
proc sort data=sashelp.class out=class nodupkey; by age; run;
data _null_;
set class;
call execute(cat('proc print data=sashelp.class; where age=',strip(put(age,best.)),';run;');
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.