The following code stores the number 30 into macro variable x, but it stores it as a character value, correct?
Given that, how does the following where clause work? If age is stored as numeric and the macro variable x as character, the where clause is conditioning on numeric variable greater than character variable. Why does this work?
%let x=30;
proc sql;
select *
from table
where age>&x;
quit;
You cannot combine or confuse macro variables with SAS variables. A macro variable is text, but that has nothing to do with how SAS uses it when SAS executes — SAS just replaces the macro variable with its value.
The following code stores the number 30 into macro variable x, but it stores it as a character value, correct?
Given that, how does the following where clause work?
where age>&x;
when executed, &x is replaced by 30 and so this SAS code is perfectly valid
where age>30;
The same way that this where clause works:
where age>30
The macro PRE-processor just passes the generated text over to SAS to interpret. SAS will interpret the text the same way it would have interpreted the same text given to it directly from the program file.
Thanks for the responses everyone!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.