DATA Step, Macro, Functions and more

copy multiple datasets

Accepted Solution Solved
Reply
Super Contributor
Posts: 506
Accepted Solution

copy multiple datasets

Hello Everyone,

 

Is there any way to shorten the below code since all "have" files are from the same lib?

 

Thank you,

 

HHCFX

 

data want; set libname.have1 libname.have2 libname.have3 libname.have4;run;

 

 


Accepted Solutions
Solution
3 weeks ago
Super User
Posts: 10,239

Re: copy multiple datasets

Then there's no way to reduce the set statement. Unless you have some criteria that helps you in selecting your datasets from dictionary.tables and putting all dataset names (including the library) into a macro variable.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

View solution in original post


All Replies
Super User
Posts: 10,239

Re: copy multiple datasets

Use a wildcard:

set libname.have:;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super Contributor
Posts: 506

Re: copy multiple datasets

Posted in reply to KurtBremser
oh, my example is a bit mis-leading.
the file I have are not all share the same name.
it is random, say ab1 cd3 dxyz22
Hoang
Solution
3 weeks ago
Super User
Posts: 10,239

Re: copy multiple datasets

Then there's no way to reduce the set statement. Unless you have some criteria that helps you in selecting your datasets from dictionary.tables and putting all dataset names (including the library) into a macro variable.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super Contributor
Posts: 506

Re: copy multiple datasets

[ Edited ]
Posted in reply to KurtBremser

Thanks for your info.

I hope it could be something like libname.( list of datasets...);

New Contributor
Posts: 4

Re: copy multiple datasets

Yes, this should be achieved, because you already have the data sets which are in numbered range lists. You can try below:

 

data want; 
   set libname.have1-libname.have4;
run;
Pankajwa
PROC Star
Posts: 1,803

Re: copy multiple datasets

Hi @hhchenfx  Try to read the dataset names from dictionary tables and create a list macrovar. Then call the macrovar in your set statement. This can help you avoid typing 

Super User
Posts: 23,720

Re: copy multiple datasets

Following up on @novinosrin suggestion:

 

%let myLib=WORK;

proc sql noprint;
select catx(".", "&myLib",  memname) into :name_list separated by " "
from sashelp.vtable
where libname=upcase("&myLib.");
quit;


data want;
set &name_list;
run;

This approach works if you have less than 1500+ variables due to the length restrictions of a SAS macro variable.

 


@hhchenfx wrote:

Hello Everyone,

 

Is there any way to shorten the below code since all "have" files are from the same lib?

 

Thank you,

 

HHCFX

 

data want; set libname.have1 libname.have2 libname.have3 libname.have4;run;

 

 


 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 122 views
  • 5 likes
  • 5 in conversation