This tutorial explains the difference between SYMPUT and SYMGET in SAS.
SYMGET : To get macro variable value in a data step.
Example 1 : Creating a single macro variable
*Creating a macro variable;Example 2 : Creating multiple macro variables
data _null_;
set sashelp.class;
if _N_ = 1 then do;
call symput('nvar', name);
end;
run;
%put &nvar;
*Get macro variable value in a dataset;
data want;
var1=symget('nvar');
run;
*Creating macro variables;
data _null_;
set sashelp.class;
call symput('nvars' || strip(_n_), name);
run;
%put &nvars1 &nvars2 &nvars3;
* Number of rows;
data _null_;
if 0 then set sashelp.class nobs=n;
call symput ('nrows',n);
run;
*Get macro variable value in a dataset;
data want (drop = i);
do i=1 to &nrows.;
var1=symget(cats('nvars',i));
output;
end;
run;
nice
ReplyDeleteReally insightful , thanks . my first time with macros
ReplyDeleteYour interview questions are really helpful for revision as well. Thank you so much for helping out everyone. Your great experience and expertise is really creating wonders.
ReplyDeleteCan u explain it with simple examples
ReplyDeleteIt was very helpful. Thank you.
ReplyDelete