BookmarkSubscribeRSS Feed
Rasheed
Calcite | Level 5

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;

24 REPLIES 24
mingfeng07
Fluorite | Level 6

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;

Rasheed
Calcite | Level 5

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

Tom
Super User Tom
Super User

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.

Rasheed
Calcite | Level 5

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;

Reeza
Super User

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;

Rasheed
Calcite | Level 5

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

LinusH
Tourmaline | Level 20

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

Data never sleeps
Rasheed
Calcite | Level 5

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

Reeza
Super User

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;

Rasheed
Calcite | Level 5

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; 

Reeza
Super User

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?

Rasheed
Calcite | Level 5

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

Rasheed
Calcite | Level 5

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

Rasheed
Calcite | Level 5

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

sas-innovate-2024.png

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.

 

Register now!

How to connect to databases in SAS Viya

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.

Discussion stats
  • 24 replies
  • 1935 views
  • 0 likes
  • 6 in conversation