I Have created a macro for creating patient profiles.
%macro patprof ( subjid= );
..
..
..
..
%mend;
I have 550 patients in my study and I am calling my macro for every individual patient.
for example :-
%patprof(subjid= 101);
%Patprof(subjid=102);
%patprof(subjid=109);
is there any way that which improves my macro code so that I don't need to call my macro all 550 times for each patient.
any help is appreciated.
Ok, so then here is something that could work (I am using sashelp.class data set, and I want to split the data based on the name):
proc sql;
select cat(" '" || name ||" ' ") into: list_name separated by ","
from sashelp.class;
quit;
%macro nada();
%do i = 1 %to 19;
data name_&i.;
set sashelp.class;
if name = %scan("&list_name", &i., ",");
run;
%end;
%mend;
%nada();
Ok, so this is what I am hoping to do:
For you the above code could translate into something like this:
proc sql;
select subjid into: list_ids separated by ","
from your_master_data;
quit;
This macro variable called list_ids should be a string that looks like this: 101, 102, 109,143,165,..., 550
Then the next part:
%macro nada();
%do i = 1 %to 550;
data step....
....
if subjid = %scan("&list_ids", &i., ",");
...
run;
%end;
%mend;
%nada();
So, you want to add the %do i = 1 %to 550:
But you also want to add the if subjid = %scan("&list_ids", &i., ","); in your data step.
Let me know if this makes any sense.
Anca.
One quick way is to include a do-loop in your macro BUT this requires that your IDs are consecutive:
%macro patprof ( );
%do subjid = 1 %to 550;
..
..
..
..
%end;
%mend;
Now call the macro just once:
%patprof();
The problem is subjids are not consecutive..
Ok, so then here is something that could work (I am using sashelp.class data set, and I want to split the data based on the name):
proc sql;
select cat(" '" || name ||" ' ") into: list_name separated by ","
from sashelp.class;
quit;
%macro nada();
%do i = 1 %to 19;
data name_&i.;
set sashelp.class;
if name = %scan("&list_name", &i., ",");
run;
%end;
%mend;
%nada();
Ok, so this is what I am hoping to do:
For you the above code could translate into something like this:
proc sql;
select subjid into: list_ids separated by ","
from your_master_data;
quit;
This macro variable called list_ids should be a string that looks like this: 101, 102, 109,143,165,..., 550
Then the next part:
%macro nada();
%do i = 1 %to 550;
data step....
....
if subjid = %scan("&list_ids", &i., ",");
...
run;
%end;
%mend;
%nada();
So, you want to add the %do i = 1 %to 550:
But you also want to add the if subjid = %scan("&list_ids", &i., ","); in your data step.
Let me know if this makes any sense.
Anca.
Thanks a lot Anca. It was really helpful.
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.