DATA Step, Macro, Functions and more

repeat same prco using macro

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 76
Accepted Solution

repeat same prco using macro

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,

 

 

 


Accepted Solutions
Solution
‎08-22-2016 01:41 PM
Super User
Super User
Posts: 7,065

Re: repeat same prco using macro

Posted in reply to Xiaoningdemao

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


All Replies
Super User
Posts: 5,515

Re: repeat same prco using macro

Posted in reply to Xiaoningdemao

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.

Solution
‎08-22-2016 01:41 PM
Super User
Super User
Posts: 7,065

Re: repeat same prco using macro

Posted in reply to Xiaoningdemao

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);
 
Frequent Contributor
Posts: 76

Re: repeat same prco using macro

Dear Tom,

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

Best wishes.
☑ This topic is solved.

Need further help from the community? Please ask a new question.

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