- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Everyone,
I need to perform a check of macro variable (&n1 and &n2) value inside %DO loop.
So with count=1, the Macro will not return anything since &n&count turns to &n1 which has value of 'aa'
With count=2, Macro will run.
Can you please help to fix that IF statement below?
Thank you,
HHCFX
%let n1=aa;
%let n2=bb;
%Macro check(count=);
%IF &n&count!='aa' %then %do;
%put code working;
%end;
%mend;
%check(count=1);
%check(count=2);
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Try this:
%let n1=aa; %let n2=bb; %Macro check(count=); %IF &&n&count.=aa %then %do; %put code working; %end; %mend; %check(count=1); %check(count=2);
The &&var&othervar is called "indirect reference". In effect the the first 2 && resolve to one & and holds that while the other bits var&othervar resolve, then use &<resolved>.
Note that your comparsion with 'aa' was NEVER going to work without providing quotes in the values as the macro language works differently than the data step. EVERYTHING in the macro language is text so quotes are seldom needed unless the value has to resolve with a quote (and be prepared for lots of headaches getting them to work).
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Try this:
%let n1=aa; %let n2=bb; %Macro check(count=); %IF &&n&count.=aa %then %do; %put code working; %end; %mend; %check(count=1); %check(count=2);
The &&var&othervar is called "indirect reference". In effect the the first 2 && resolve to one & and holds that while the other bits var&othervar resolve, then use &<resolved>.
Note that your comparsion with 'aa' was NEVER going to work without providing quotes in the values as the macro language works differently than the data step. EVERYTHING in the macro language is text so quotes are seldom needed unless the value has to resolve with a quote (and be prepared for lots of headaches getting them to work).
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you so much!
HHC