BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
CHL0320
Obsidian | Level 7

Hi, community,

 

I am seeking an automatic way to read all SAS data in a folder to do the same process. 

Thank you so much.

 

Here is my manual code. It works but takes time to key in all filenames. 

/**/

Libname path "C:\myfolder\SAS";
Data &filename;
set path.&filename;
sas statements;

.

.
run;

%let filename=a;

%let filename=b;

............

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
proc sql;
    select memname into :names separated by ' ' from dictionary.tables where upcase(libname)='PATH';
quit;

%macro dothis;
    %do i=1 %to %sysfunc(countw(&names));
        %let thisname = %scan(&names,&i,%str( ));
        data &thisname;
            set path.&thisname;
            /* other sas statements */
        run;
    %end;
%mend;

%dothis
--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26
proc sql;
    select memname into :names separated by ' ' from dictionary.tables where upcase(libname)='PATH';
quit;

%macro dothis;
    %do i=1 %to %sysfunc(countw(&names));
        %let thisname = %scan(&names,&i,%str( ));
        data &thisname;
            set path.&thisname;
            /* other sas statements */
        run;
    %end;
%mend;

%dothis
--
Paige Miller
CHL0320
Obsidian | Level 7
Thank you. It works like magic.
andreas_lds
Jade | Level 19

So every dataset in the library has to be processed using the same statements. I am sure that such tasks have been solved many times - you will find them using the search function.

Here's just a recipe:

  1. Write the step that process one file, have it fully tested.
  2. Convert the step to a macro, a parameter for the dataset is mandatory.
  3. Test the macro.
  4. Write a data step reading sashelp.vtable with where statement to process only the datasets in your library.
  5. use call execute to execute the macro for each dataset found.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 828 views
  • 2 likes
  • 3 in conversation