BookmarkSubscribeRSS Feed
Josh
Calcite | Level 5
Ok SYMPUT I use all the time and in preference to SELECT INTO : in PROC SQL but SYMGET I just don't get it. In a data step what does x=symget('macrovar') achieve that x="&macrovar" does not?
3 REPLIES 3
WillDobson
Calcite | Level 5
Hi Josh,

You can use a datastep variable to determine which macro variable is retreived using symget:
[pre]
data this;
do x = 1 to 3; output;
call symput(put(x,words5.),x);
end;
run;

data that;
set this;
y = symget(put(x,words5.));
run;
[/pre]
The other main feature I use it for is that it can retreive a macro variable which has been set by call symput from within the same step:
[pre]
%symdel me;
data also;
call symput("me","mememe");
put 'Value of &me: ' "&me."; *Not found;
tst = symget("me");
put 'Value of &me: ' tst; *Found;
run;
[/pre]
Regards,
-- Will Message was edited by: WillDobson
data_null__
Jade | Level 19
Short answer: Symget is executable.

Plus check out symgetN to create a numeric value from a macro variable value.
chang_y_chung_hotmail_com
Obsidian | Level 7
Interesting that you mentioned the symget function. I remember vividly this sas-l thread about the certification exam but also about the not-well-known-back-then (and now either, it seems) symget function. 🙂

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1980 views
  • 0 likes
  • 4 in conversation