BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
daszlosek
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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;

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User

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;
daszlosek
Quartz | Level 8

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

Reeza
Super User

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;

daszlosek
Quartz | Level 8

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 3803 views
  • 3 likes
  • 3 in conversation