Hi, All,
I have a macro variable (%let id = T1234;) and I would like the value of a variable to be equal to this macro variable. It should like like so:
col1 col2
1 T1234
2 T1234
...
I've tried the following: proc sql; select col1, "&id." as col2 from some_table.
And this doesn't work. I end up with:
col1 col2
1 &id.
2 &id.
I've also tried using a data step (col2 = '"&id.";). This doesn't work either - only the first character will print (I assume because the second character may be numeric?). The results look something like this:
col1 col2
1 T
2 T
Any advice or help would be greatly appreciated.
Thanks,
c
This should work, just make sure you declare the macro variable before you create the table AND that it's in double quotes not single quotes.
proc sql;
select col1, "&id." as col2
from some_table;
Not sure what's the problem, here is my test
%let id=T1234;
data want;
do col1=1,2;
col2="&id";
output;
end;
run;
This should work, just make sure you declare the macro variable before you create the table AND that it's in double quotes not single quotes.
proc sql;
select col1, "&id." as col2
from some_table;
That fixed it, thanks. The problem seemed to be that I wasn't declaring the value first. Thank you.
Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.
Explore Now →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.