DATA Step, Macro, Functions and more

Macro help

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

Macro help

I have the follwing macro. It does not show any error but is not executed either. Please help me fix it. Thanks.

%macro surv(filenm, str=, fin=);

%let k=&str; l=&fin; %let name=&filename;

%let var1=a_cmb; %let var2=a_ip; %let var3=a_er;

%let var4=d_cmb; %let var5=d_ip; %let var6=d_er;

%do i=&k %to &l;

    var=&&var&i; *(' tried "&&var&i" also );

   title "PD_file-&name, event-&var";

   proc phreg data=event_pd_&name;

   model &var_time*&var_event(0)=  age cci  pd / ties=efron;

   array pd_a(*) pd_q1-pd_q8;

     t=ceil(&var_time/90); pd=pd_a;

   run;

   title;

%end;

%mend;

%surv(min, str=4, fin=5);


Accepted Solutions
Solution
‎10-12-2012 08:02 PM
Respected Advisor
Posts: 3,124

Re: Macro help

Hi,

I have not read through your code, but one thing pop out instantly: You did not define &filename in your macro (unless you did it somewhere else, and then 'filenm' was defined but never called), yet you call for it. My guess is that you typo parameter "filenm" with 'filename'. Not sure if this is the cause,  but it just does not seem right.

Haikuo

View solution in original post


All Replies
Solution
‎10-12-2012 08:02 PM
Respected Advisor
Posts: 3,124

Re: Macro help

Hi,

I have not read through your code, but one thing pop out instantly: You did not define &filename in your macro (unless you did it somewhere else, and then 'filenm' was defined but never called), yet you call for it. My guess is that you typo parameter "filenm" with 'filename'. Not sure if this is the cause,  but it just does not seem right.

Haikuo

Occasional Contributor
Posts: 9

Re: Macro help

@Hai-Kuo; thanks, smart catch, but it is typo here. It was ok in the original one but problem is still there.

Respected Advisor
Posts: 3,124

Re: Macro help

options mlogic mprint symbolgen;

Then post the log, or maybe you can then figure it out yourself.

Haikuo

update: from your code,

1. "var" was not defined as macro variable, so '&var' should not be resolved.  add '%let' to  'var=&&var&i;'

2. &var_time, &var_event was not defined. What you want maybe: &var._time, &var._event

Super User
Posts: 5,099

Re: Macro help

At a minimum, start with:

The word %LET is missing from I=&fin.

What is the purpose of:  var=&&var&i;

It generates a DATA step assignment statement, without the rest of the DATA step.

Also note that you have unmatched single quotes in the comment line that you added.  It's not clear if that's really part of the code you ran or not but get rid of unmatched quotes.

And of course, whatever the results, show us the earlier pieces of the code.  Some of these macro variables are coming out of nowhere.

Good luck.

Occasional Contributor
Posts: 9

Re: Macro help

Lots of thanks to both of you!!! Yes, code ran.

@ Haikuo: Enabling Options, comments 1 & 2 were of great help.

@ Astounding: adding %let worked. &&var&i added to pick and assign values selectively.

🔒 This topic is solved and locked.

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

Discussion stats
  • 5 replies
  • 254 views
  • 6 likes
  • 3 in conversation