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.
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.);
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.
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;
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!
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.
Ready to level-up your skills? Choose your own adventure.