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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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