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

Hi all,

I want to reuse the text from a macro to combine some data set using the SET statement but the name of the datasets I want to combine are macro variables (see the example below), therefore the only result in the data set "Lis_prob_&variable" is the information of the last data set "prob_mar130". Any suggestion?

 

%MACRO example (variable=);

SAS statements

;

ODS OUTPUT ModelANOVA = prob_&variable;
DATA List_prob_&variable;
SET prob_▮ IF effect = "&variable";
RUN;

%MEND example;

 

%example (variable = mar1);
%example (variable = mar2);
;
%example (variable = mar130);

 

Thank you in advance

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Given your example it doesn't make a heck of a lot of sense to use a macro in the first place. Can you expand your problem description? 

 

That at being said, you can add an append at the end of your macro to append the results to a master table. 

You can use the : to specify all datasets starting with a specific prefix. If you use the same prefix for other tables this will not work.  

 

Data want;
Set list_prob_: indsname =source;
Dataset_source=source;
Run;

View solution in original post

3 REPLIES 3
Reeza
Super User

Given your example it doesn't make a heck of a lot of sense to use a macro in the first place. Can you expand your problem description? 

 

That at being said, you can add an append at the end of your macro to append the results to a master table. 

You can use the : to specify all datasets starting with a specific prefix. If you use the same prefix for other tables this will not work.  

 

Data want;
Set list_prob_: indsname =source;
Dataset_source=source;
Run;
Fersal
Calcite | Level 5

Thanks, even with my bad explanation of the issue, you were able to understand the essence what I wanted to do, finally I got to combine the datasets using ":" and using some conditional statements, I tried with the append procedure but it doesn't work since the structure of some datasets were not exactly the same (eg. length of some variables).

Astounding
PROC Star

I'm not certain of the structure of the ODS output data sets here ... if they always use the same structure you could modify the macro:

 

%MACRO example (variable=);

SAS statements

;

ODS OUTPUT ModelANOVA = prob_&variable;
DATA List_prob_&variable;
SET prob_▮ IF effect = "&variable";
RUN;

proc append data=prob_&variable base=all_anova_results;

run;

%MEND example;

 

Be aware that this will always add to existing results (assuming it works) and never replace what was there before.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 3 replies
  • 572 views
  • 0 likes
  • 3 in conversation