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