As the first step in the decommissioning of sasCommunity.org the site has been converted to read-only mode.
Here are some tips for How to share your SAS knowledge with your professional network.
Passing Macro Variables
Q: How can I pass macro variable values from one macro to another. Both are called from top level; this is not a routine calling a subroutine and user does not want to %global the values.
- in first macro save the local macro variables into a data set using sql dictionary.macros;
- in second macro use call execute to 'reconstitute' the macro variables.
Save in Data Set
options mprint; %let a = b; %macro one(data=sashelp.class ,testing=1); %put &sysmacroname &=data; proc sql; create table macro_variables as select scope, name, value from dictionary.macros where scope eq "&sysmacroname" and not (name like 'SQL%'); quit; %if &testing %then %do; proc print;title3 &syslast; %end; run; %mend one; %one() %symdel a; %macro two(testing=1); DATA _null_; attrib statement length = $128; do until(endofile); set macro_variables end = endofile; putlog name= value=; statement = catx(' ','%let',name,'=',value,';'); putlog statement=; call execute(statement); end; stop; run; %if &testing %then %put _local_; run; %mend; %put info: global m-vars;; %put _user_; %two() %put _global_;
- not a good idea; this trick is not intuitive
- the second macro receives all the macro variables of the first macro call and there is no way of knowing what is in the data set
- better to allocate global macro variables and pass the values into each macro; e.g.;
%let in_data = sashelp.class; %one(data=&in_data) %two(data=&in_data)
Save in Macro Variable Sysparm
options sysparm = 'a=b,c=def,data=sashelp.class';
Unpack with Parse Sysparm
- The original Q for this thread was posted to SAS-L on 2013-11-21, post number 351328
--Ronald_J._Fehd macro.maven == the radical programmer (talk) 20:11, 26 May 2015 (CDT)