BookmarkSubscribeRSS Feed
jdsdog10
Calcite | Level 5

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;

 

4 REPLIES 4
Reeza
Super User
It's better to think of it as text. All macro's do is generate SAS code that must be valid. The code above is valid.

Macro variables should be considered TEXT not Character/Numeric.

If age was a character variable that code wouldn't work.
PaigeMiller
Diamond | Level 26

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;

 

--
Paige Miller
Tom
Super User Tom
Super User

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.

jdsdog10
Calcite | Level 5

Thanks for the responses everyone!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 4 replies
  • 927 views
  • 0 likes
  • 4 in conversation