Combining data set into a macro

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 10
Accepted Solution

Combining data set into a macro

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


Accepted Solutions
Solution
‎03-31-2016 08:53 AM
Super User
Posts: 19,167

Re: Combining data set into a macro

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


All Replies
Solution
‎03-31-2016 08:53 AM
Super User
Posts: 19,167

Re: Combining data set into a macro

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;
Occasional Contributor
Posts: 10

Re: Combining data set into a macro

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).

Super User
Posts: 5,367

Re: Combining data set into a macro

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.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 264 views
  • 0 likes
  • 3 in conversation