SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Combining multiple data sets

Reply
Frequent Contributor
Posts: 84

Combining multiple data sets

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;

Occasional Contributor
Posts: 5

Re: Combining multiple data sets

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;

Frequent Contributor
Posts: 84

Re: Combining multiple data sets

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

Super User
Super User
Posts: 6,500

Re: Combining multiple data sets

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.

Frequent Contributor
Posts: 84

Re: Combining multiple data sets

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;

Super User
Posts: 17,828

Re: Combining multiple data sets

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;

Frequent Contributor
Posts: 84

Re: Combining multiple data sets

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

Super User
Posts: 5,256

Re: Combining multiple data sets

Why not a macro?A And Reezas sugestion is not a macro program but the use of a macro variable.

Data never sleeps
Frequent Contributor
Posts: 84

Re: Combining multiple data sets

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

Super User
Posts: 17,828

Re: Combining multiple data sets

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;

Frequent Contributor
Posts: 84

Re: Combining multiple data sets

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; 

Super User
Posts: 17,828

Re: Combining multiple data sets

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?

Frequent Contributor
Posts: 84

Re: Combining multiple data sets

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

Frequent Contributor
Posts: 84

Re: Combining multiple data sets

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

Frequent Contributor
Posts: 84

Re: Combining multiple data sets

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

Ask a Question
Discussion stats
  • 24 replies
  • 872 views
  • 0 likes
  • 6 in conversation