BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
shasank
Quartz | Level 8

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. 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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';

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Reeza
Super User
Do you want the data sets copied to a new library? Or do you want a new dataset with all the results combined into one dataset in a new library?

Tom
Super User Tom
Super User

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 805 views
  • 0 likes
  • 4 in conversation