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: 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
  • 1024 views
  • 2 likes
  • 3 in conversation