Hey All!
Was hoping that you could help me with this.
I am currently running a macros, in which I am creating X number of datasets (code is below).
%MACRO RunANOVA (Variable = , Number = );
ODS TRACE ON;
PROC ANOVA
DATA = Work.data
ORDER = INTERNAL;
CLASS StateCd;
MODEL &Variable = StateCd;
RUN;
QUIT;
ODS TRACE OFF;
ODS OUTPUT OverallANOVA = WORK.ANOVAResults&Number
ModelANOVA = WORK.ModelResults&Number;
PROC ANOVA
DATA = Work.data
ORDER = INTERNAL;
CLASS StateCd;
MODEL &Variable = StateCd;
RUN;
QUIT;
DATA WORK.ANOVAResults&Number;
RETAIN Variable Dependent FValue ProbF;
SET WORK.&Number;
KEEP Variable Dependent FValue ProbF;
Variable = &Number;
Run;
%MEND RunANOVA;
I can then merge all the datasets together using the following code below.
DATA work.ANOVAResults;
SET WORK.ANOVAResults:;
RUN;
My question is that is there a way manipulate the Data step from the code above to merge only every nth dataset?
For example, I have a total of 100 datasets (HypRslt.ANOVAResults1-100) and I want to merge every 10th dataset. I know that I could use the following code below to get this done.
DATA Work.ANOVAResults;
SET WORK.ANOVAResults10
WORK.ANOVAResults20
WORK.ANOVAResults30
WORK.ANOVAResults40
WORK.ANOVAResults50
WORK.ANOVAResults60
WORK.ANOVAResults70
WORK.ANOVAResults80
WORK.ANOVAResults90
WORK.ANOVAResults100;
RUN;
However, I was wondering if there was a simpler way to code this, so that if I wanted to merge very 9th dataset instead of every 10th dataset, I could easily do this without having to write out the name of each dataset.
If you could let me know if this is possible, or if you need more information, it would be greatly appreciated.
Thanks,
Alex
Something like this?
%macro loop(skip=);
%local i;
%do i=1 %to 100 %by &skip.;
WORK.ANOVARESULTS&i.
%end;
%mend;
data RESULTS;
set %loop(skip=9);
run;
Something like this?
%macro loop(skip=);
%local i;
%do i=1 %to 100 %by &skip.;
WORK.ANOVARESULTS&i.
%end;
%mend;
data RESULTS;
set %loop(skip=9);
run;
Yes that is exactly what I needed. Did not think to do another macro
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.