Good morning!
I have a question about using macro in sas. I want to check the log-log plot for many variables(more than 10). The program is the same for each of them. So instead of have 10 same repeated programs. I want to use macro, but I don't knew how to use extract the elemnt in macro variable one by one. My code is:
%let plot= age sex hight;
%macro plot;
%do i=1 %to 10;
proc lifetest data=modeldata plot=(lls) ;
time followup*pass(0);
strata &plot[i];
ods select 'LOGLOGS Plot';
run;
%end;
%mend plot;
But it doesn't work. I feel the problem is wirh strata &plot[i];
Can you help me fix this code? Or come up with a better way to do so?
Thank you very much!!
Best wishes,
Macro variables are just strings, not arrays. So use some simple string processing functions.
%macro plot(varlist);
%local i;
%do i=1 %to %sysfunc(countw(&varlist));
proc lifetest data=modeldata plot=(lls) ;
time followup*pass(0);
strata %scan(&varlist,&i) ;
ods select 'LOGLOGS Plot';
run;
%end;
%mend plot;
%plot(age sex hight);
You'll have to show us what the program would look like without macro language. You only have to show the program for 1 variable, but it has to be working code. If the code you show doesn't work for 1 variable, macro language would only generate nonworking code for 10 variables ... not a useful result.
Macro variables are just strings, not arrays. So use some simple string processing functions.
%macro plot(varlist);
%local i;
%do i=1 %to %sysfunc(countw(&varlist));
proc lifetest data=modeldata plot=(lls) ;
time followup*pass(0);
strata %scan(&varlist,&i) ;
ods select 'LOGLOGS Plot';
run;
%end;
%mend plot;
%plot(age sex hight);
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.