BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

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,

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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);
 

View solution in original post

3 REPLIES 3
Astounding
PROC Star

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.

Tom
Super User Tom
Super User

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);
 
Xiaoningdemao
Quartz | Level 8
Dear Tom,

Thank you very much!!!
This is exactly what I want!!!

Best wishes.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1284 views
  • 2 likes
  • 3 in conversation