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);
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).
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).
Thank you so much!
HHC
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.