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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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