Hello all, I am trying to make three datasets from a macro that uses the macro variable name to make the name of the dataset. My issues arises from needing to make multiple datasets from different output and I want to change the name of the dataset so there are a total of three datasets with three different names.
Here is my code and an example of what I am trying to do:
%macro tab1 (var);
PROC SORT DATA = main OUT= &var ;
BY &var ;
RUN;
PROC FREQ DATA = &var ;
&POPULATION;
TABLES strata1 * strata2 * trtp * peoyn / nocol nopercent cmh;
by &var;
output cmh relrisk out= &var; /*<----- want this dataset to be renamed &var1*/
run;
ODS TRACE ON;
ODS OUTPUT ParameterEstimates= &var; /*<----- want this dataset to be renamed &var_INT*/
proc logistic data=&var;
STRATA strata1 strata2;
&POPULATION;
class trtpn &var;
model peoynn = trtpn &var trtpn*&var;
run;
ODS TRACE OFF;
%mend;
%tab1 (variable_a);
%tab1 (variable_b);
The product will be six datasets named: (variable_a, variable_a1, variable_a_INT) and (variable_b, variable_b1, variable_b_INT).
Thank you for your help and let me know if youhave any questions,
Best,
Donald
If you want to use a macro variable as a prefix in a word, you must end the macro variable reference with a dot.
&var1 will make SAS look for the macro variable var1 (which probably fails), while &var.1 will create xxx1 if var contained xxx
yyy&var1.z would then create yyyxxxz
You would therefore use
output cmh relrisk out= &var.1;
and
ODS OUTPUT ParameterEstimates= &var._INT;
If you want to use a macro variable as a prefix in a word, you must end the macro variable reference with a dot.
&var1 will make SAS look for the macro variable var1 (which probably fails), while &var.1 will create xxx1 if var contained xxx
yyy&var1.z would then create yyyxxxz
You would therefore use
output cmh relrisk out= &var.1;
and
ODS OUTPUT ParameterEstimates= &var._INT;
Hello KurtBremser,
This worked like a charm!! I defienlty have alot more to learn about macro programming.
Thank you very much for your assistance,
Best,
Donald
Suggestion, use a prefix to differentiate datasets, not a suffix. SAS allows shortcut of reference names by prefixes, so later on this can be useful.
Ie append together all datasets starting with INT can be done via :
data int_master;
set int_:;
run;
Hello Reeza,
An excellent and very useful idea. Thank you for this advice, I will incorprate this structure into my programming.
Best,
Donald
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.