Hi Community,
I am a new SAS user and trying to figure out a way to create subsets of all the datasets in a library to a new library. All the datasets in the library have a variable "FolderName". All I need to to create a new library for all the rows that have FolderName="NEW". I have around 50 datasets in the library. Is there a way to do this without specifying all the names in the library?.
The dataset has 3 variables Subject FolderName City
Any help is appreciated.
Thanks.
Do all of the dataset have the variable FOLDERNAME?
If so you just need the list of member names.
libname old 'current directory';
libname new 'new directory';
proc contents data=old._all_ noprint out=contents; run;
filename code temp;
data _null_;
set contents;
by memname;
if first.memname;
file code;
put 'data new.' memname ';'
/ ' set old.' memname ';'
/ ' where foldername="NEW";'
/ 'run;'
;
run;
%include code / source2;
If not you need to specify what to do with the datasets that do not have the FOLDERNAME variable.
If you want to skip them then just add a WHERE statement to the the data _null_ step above;
where upcase(name)='FOLDERNAME';
Better (much easier): when you want to use the datasets, use them from the current library, and use the WHERE statement to get just those rows where FolderName="NEW". No need to create a whole new library.
Example:
proc freq data=yourdatasetname;
where foldername="NEW";
table city;
run;
No new library needed.
Do all of the dataset have the variable FOLDERNAME?
If so you just need the list of member names.
libname old 'current directory';
libname new 'new directory';
proc contents data=old._all_ noprint out=contents; run;
filename code temp;
data _null_;
set contents;
by memname;
if first.memname;
file code;
put 'data new.' memname ';'
/ ' set old.' memname ';'
/ ' where foldername="NEW";'
/ 'run;'
;
run;
%include code / source2;
If not you need to specify what to do with the datasets that do not have the FOLDERNAME variable.
If you want to skip them then just add a WHERE statement to the the data _null_ step above;
where upcase(name)='FOLDERNAME';
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.