Hi folks - it could seems a silly question.
I have a varlist as a result of macroA.
%macroA;
...
%put &varlist;
%mend;
I need to use the created varlist in macroA in macroB as input.
but SAS errors me that &varlist is not recognised.
please help me in this regard....
The issue is variable scope.
A macro variable created within a macro, is local, it only exists within the macro. To use the macro variable outside of the macro you need to change the scope to global, as someone has already indicated.
%global varlist;
If you're creating a macro variable using call symput, change to call symputx and use the -g option.
Within %macroA, add this statement early:
%global varlist;
That will keep it around after %macroA ends.
The issue is variable scope.
A macro variable created within a macro, is local, it only exists within the macro. To use the macro variable outside of the macro you need to change the scope to global, as someone has already indicated.
%global varlist;
If you're creating a macro variable using call symput, change to call symputx and use the -g option.
Apart from using globals, you can make each call of the macro to be substituted
by the variables list as follows :
%macro macroA;
/* Code to generate the list */
[...]
&varlist
%mend macroA;
%macro macroB;
%let variables=%macroA;
[...]
%mend macroB;
thanks...
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.