user2873428
user2873428

Reputation: 11

if then else loop macro in sas

i'm trying to create if else loop macro in sas to create dummies for variables in a large dataset. the code i used is:

enter code here



%macro dummy(x,y,z);
data handle;
set handle;
%if &x='&y' %then %do;
&z=1;
%end;
%else %do; 
&z=0;
%end;
run;
%mend dummy;

and then i evoked the macro

%dummy(age_restriction,02,age_res1)

it created the var age_res1 but the condition did not get implied

using % sign with if else do directly uses the condition and does not produce the exact code but the condition also didn't ran

Upvotes: 1

Views: 521

Answers (1)

Michael Kersten
Michael Kersten

Reputation: 427

To be honest I dont get the question. But I found one error in the following line:

%if &x='&y' %then %do;

You have to replace the single quotation marks with double quotation marks to allow resolution of macro variable y.

And you should get into the diffrences between compile and run time regarding macro code. Information about this topic can be found here among others: http://www2.sas.com/proceedings/sugi27/p067-27.pdf

Upvotes: 1

Related Questions