DATA Step, Macro, Functions and more

SYMGET

Reply
Occasional Contributor
Posts: 11

SYMGET

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?
Occasional Contributor
Posts: 10

Re: SYMGET

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
Respected Advisor
Posts: 3,799

Re: SYMGET

Short answer: Symget is executable.

Plus check out symgetN to create a numeric value from a macro variable value.
Regular Contributor
Posts: 241

Re: SYMGET

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. :-)
Ask a Question
Discussion stats
  • 3 replies
  • 240 views
  • 0 likes
  • 4 in conversation