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

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
Barite | Level 11
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
Barite | Level 11

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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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