BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
boyandhisrobot
Calcite | Level 5

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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; 

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

Not sure what's the problem, here is my test

 

%let id=T1234;

data want;
do col1=1,2;
col2="&id";
output;
end;
run;
Reeza
Super User

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; 
boyandhisrobot
Calcite | Level 5

That fixed it, thanks.  The problem seemed to be that I wasn't declaring the value first.  Thank you.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 7759 views
  • 0 likes
  • 3 in conversation