BookmarkSubscribeRSS Feed
scb
Obsidian | Level 7 scb
Obsidian | Level 7

I would like to do the following: libname concatenation.

 

libname testyear ("D:\test\1998","D:\test\1999","D:\test\2000","D:\test\2001");

 

Is there any better to do this as the year will increase? Please advice.  Thanks.

 

 

3 REPLIES 3
Kurt_Bremser
Super User

Create the string of directory names in a data step, and store it in a macro variable:

data _null_;
length libstring $500;
do year = 1998 to 2001;
  libstring = catx(',',libstring,quote("D:\test\" !! put(year,z4.)));
end;
call symputx('libstring',libstring);
run;

libname testyear (&libstring.);
SASKiwi
PROC Star

Why split your data into yearly folders? You can date stamp your file names to indicate which year / month / day they are for. You can easily end up creating a maintenance problem by having directories for every period. It is a whole lot easier not to split SAS data by date into separate folders, but to date stamp them instead - your LIBNAME example would just be D:\Test and not change.

andreas_lds
Jade | Level 19

If xcmd is enabled, try:

 

filename oscmd pipe "dir /b d:\test";

data _null_;
   length pathList $ 500;
   retain pathList;

   infile oscmd end=jobDone;
   input;

   pathList = catx(',', pathList, quote(cats("d:\test\", _infile_)));


   if jobdone then do;
      call execute(cats('libname testyear (', pathList, ');'));
   end;

run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 3 replies
  • 962 views
  • 0 likes
  • 4 in conversation