DATA Step, Macro, Functions and more

How to use conditional statements with a macro

Reply
Frequent Contributor
Posts: 75

How to use conditional statements with a macro

Hello all,

so I am working on this program:

%macro sc(i,resdata);
proc iml;
start delcol(x,i);
return(x[,setdif(1:ncol(x),i)]);
finish;

use test&i;
read all into x;
x=delcol(x,{1,2}); print x;

use &resdata;
read all var {Resid} into y where(id=(&i+1)&Resid^=.); print y;

sc=x*y; print sc;
quit;
%mend;

I am getting this error: WARNING: Apparent symbolic reference RESID not resolved.

I believe its from the part in the code I bolded. I think the macro thinks that resid is an input variable (like i and resdata) but it is really part of the where condition. Is there anyway I can tell the macro that &Resid is not part of the inputs?
Super Contributor
Super Contributor
Posts: 3,174

Re: How to use conditional statements with a macro

It appears you are attempting to use the ampersand character as an operator "AND" condition. Separate the "&" from the SAS variable "Resid" so that SAS does not interpret the string as a macro variable.

Scott Barry
SBBWorks, Inc.
SAS Employee
Posts: 58

Re: How to use conditional statements with a macro

Or try quoting the &...

where(id=(&i+1)%nrquote(&)Resid^=.); print y; sc=x*y; print sc; quit;
Ask a Question
Discussion stats
  • 2 replies
  • 107 views
  • 0 likes
  • 3 in conversation