Help using Base SAS procedures

Apply any procedure to all the files in a library

Accepted Solution Solved
Reply
Contributor
Posts: 32
Accepted Solution

Apply any procedure to all the files in a library

Hi, 

 

I have around 20 files in a library. I want to apply Proc means to all the files in the library using a macro than writing all 20 file names.

 

It should take all the file names automatically if I specify the library name.

 

Thanks 

 

 

 


Accepted Solutions
Solution
‎12-28-2015 10:30 PM
Super User
Posts: 17,818

Re: Apply any procedure to all the files in a library

Try one of the other CAT functions.
There's CATT, CATX, CAT. Most likely CATT, which only trims trailing spaces so you can add a space before the NMISS.

View solution in original post


All Replies
Super User
Posts: 17,818

Re: Apply any procedure to all the files in a library

You can get all the dataset names in a library from sashelp.vtable and call execute should be straightforward. You also don't necessarily need a macro depending on your needs. Here's a demo - untested. 

 

%let lname=WORK; 

data dnames; 
set sashelp.vtable;
 where libname=upper("&lname"); 
run; 

data _null_; 
set dnames; 
str=cats("proc means data=&lname..", memname, "; run;"); 
call execute(str); 
run;

 

Contributor
Posts: 32

Re: Apply any procedure to all the files in a library

Hi,

 

Thanks.

 

The code is working. 

 

I was actually looking to know about missing values in each dataset using proc means, NMISS option. 

 

As cats function is removing the trailing and leading blanks I am unable to give the NMISS option.

 

Could you please look into it.

 


data _Null_;
set metfile;
str=cats("proc means data=&library..", memname, "nmiss", "; run;");
call execute(str);
run;

 

It is generating the statements

 

proc means data=TASK3.DEMOSSUBMITnmiss; run;
ERROR: File TASK3.DEMOSSUBMITNMISS.DATA does not exist.

 

where Nmiss is mixing up with the dataset name.

 

 

Solution
‎12-28-2015 10:30 PM
Super User
Posts: 17,818

Re: Apply any procedure to all the files in a library

Try one of the other CAT functions.
There's CATT, CATX, CAT. Most likely CATT, which only trims trailing spaces so you can add a space before the NMISS.
Contributor
Posts: 32

Re: Apply any procedure to all the files in a library

cool. Its Working. 

 

Thanks.

 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 297 views
  • 1 like
  • 2 in conversation