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. 🙂

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 1587 views
  • 0 likes
  • 4 in conversation