I have multiple data sets named
dsnAC16 dsnAC17 dsnAC18 dsnAC19 dsnAC110.........dsnAC125
dsnAC26 dsnAC27 dsnAC28 dsnAC29 dsnAC210.........dsnAC225
.
.
.
dsnAC56 dsnAC57 dsnAC58 dsnAC59 dsnAC510.........dsnAC525
I want to combine all above data set and I am using following code but getting some errors pls guide
%let i=5; %let pat=20;
data combineAC;
set
do %let k = 1 to &i;
do %let h= %eval(1+&i) to %eval(&pats+&i);
dsnAC&k&h
end;
end;
run;
You can try this.
%macro test;
%do i=1 %to 5;
%do j=6 %to 25;
dsnAC&i.&j
%end;
%end;
%mend;
data combineAC;
set %test;
run;
Thanks for your reply
actually I have already complete this program through macro as you mentioned but the problem is that I want to do this without macro
I am working on simulation and want to avoid macro loop for efficient simulation that can run faster
Use of macro will not impact the speed of execution.
A macro just generates code. It takes almost no time at all.
It is the code that will impact the speed.
For an optimal method to code your simulation you probably need to give us more information on what you actually want to do.
Thank you very much for your reply
Actually I am simulating 500 samples from multivariate normal distribution under the replicated crossover design. This design is very complicated though. Then for each simulated sample I have to run 2000 bootstrap samples. In all this task is very complicated. I generated 500 simulations and in between i need to combine some data sets I used macro do loop that takes hours of hours to perform this task. Than I red an article of Rick Wicklin about efficient simulation. Where I found that macro do loop should be avoided to make simulation run faster. That is why I am trying following code that will combine multiple data set without macro do loop but I am getting error in it
Data sets need to combine are
DsnAC16 DsnAC17 DsnAC18 DsnAC19 ...................DsnAC125
DsnAC26 DsnAC27 DsnAC28 DsnAC29 ...................DsnAC225
......
DsnAC56 DsnAC57 DsnAC8 DsnAC59 ...................DsnAC525
Code:
%let i=5; %let pat=20; data combineAC; set do k= 1 %to &i; do h= (1+&i) %to (&pat+&i); dsnAC&k&h end; end;
;
run;
Assuming all datasets start with dsnAc and you don't have other datasets that start with the letter DSNAC?
Otherwise create a macro list by querying SASHELP.VTABLE or Dictionary.Table
data want;
set dsnaC: ;
run;
I don't have any other data set except mentioned above data sets list starting with dsnAC
I want to do this task without using macro loop kindly help me in this regard I would be grateful if you could mention the code for it
Why not a macro?A And Reezas sugestion is not a macro program but the use of a macro variable.
I am working on simulation program in which I don't want to use macro loop because of time saving
I would be grateful if you could mention code because i didn't understand reeza suggestion
Ragards
Did you try the code in my first answer, mainly using the colon after the name? That appends all datasets that starts with DSNAC. If you need the dataset name you can use the INDSNAME option as well.
data want;
set dsnaC: INDSNAME=SOURCE;
DNAME=SOURCE;
run;
Thank you very much for your reply could pls mention complete code for it. Actually I have multiple data sets
DsnAC16 DsnAC17 DsnAC18 DsnAC19 ...................DsnAC125
DsnAC26 DsnAC27 DsnAC28 DsnAC29 ...................DsnAC225
......
DsnAC56 DsnAC57 DsnAC8 DsnAC59 ...................DsnAC525
And I want to combine all without macro do loop that is why I am using following code but getting some error in it
%let i=5; %let pat=20;
data combineAC;
set
do k= 1 %to &i;
do h= (1+&i) %to (&pat+&i);
dsnAC&k&h
end;
end;
;
run;
THAT IS THE COMPLETE CODE.
THE COLON IS A SAS SHORTCUT THAT TELLS IT TO SET/APPEND ALL DATASETS THAT START WITH DSNAC.
HAVE YOU TRIED IT AND IT DID NOT WORK?
Actually the data sets which I want to combine are not in series they are like
DsnAC16 DsnAC17......DsnAC125
then
DsnAC26 DsnAC27.....DsnAC225
...
DsnAC56 DsnAC57.....DsnAC525
So how could I used colon ? for this
I did the same task using macro do loop using following code and its work fine
%macro allmergeAC (a,b); data combineAC; set %do k= 1 %to &a; %do h= (1+&a) %to (&b+&a); dsnAC&k&h %end; %end; ; run;
But I want to do this without macro do loop
%mend;
%allmergeAC (&i,&pat) ;
Sorry for incorrect formatting of previous message
I did the same task using macro do loop using following code and its work fine
%macro allmergeAC (a,b);
data combineAC;
set
%do k= 1 %to &a;
%do h= (1+&a) %to (&b+&a);
dsnAC&k&h
%end;
%end;
;
run;
%mend;
%allmergeAC (&i,&pat) ;
But I want to do this without macro do loop
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.