BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hhchenfx
Rhodochrosite | Level 12

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;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

7 REPLIES 7
hhchenfx
Rhodochrosite | Level 12
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
Kurt_Bremser
Super User

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.

hhchenfx
Rhodochrosite | Level 12

Thanks for your info.

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

pjpnk
Fluorite | Level 6

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
novinosrin
Tourmaline | Level 20

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 

Reeza
Super User

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;

 

 


 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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