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

Hi,

 

I have a windows directory in which I have created a few macros as .txt files. I want to store the names of these text files in to a sas macro. The intent is that I want to declare (%include) all macros within that directory using this sas macro instead of asking user to enter all the macros one by one. Please note that each text file contains some lines of sas codes (and no data)

 

Thanks!

Mayank

1 ACCEPTED SOLUTION
4 REPLIES 4
mayankdce1
Fluorite | Level 6
Thank you for a prompt response. As a quick fix, I have created a small macro. But, I am also simultaneously looking into sasautos to get more understanding.

%macro declare_macros;
%let file_path = &toolkit.;
filename dirlist pipe "dir ""&file_path"" /b ";

data dirlist;
infile dirlist missover pad;
input filename $1000.;
run;

data _null_;
set dirlist;
id = _n_;
call symputx("nobs",strip(id));
call symput('macro' || left(put(_n_, 4.)), trim(filename));
run;

%do ii = 1 %to &nobs.;
%include "&toolkit.&&macro&ii.";
%end;
%mend declare_macros;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Thats not a quick fix, thats a very long fix, which may not work all the time and isn't portable.  

options sasautos=(&toolkit.);

Is a quick fix.

mayankdce1
Fluorite | Level 6

Thank you, again. It worked! Much simpler method.

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 4 replies
  • 1676 views
  • 4 likes
  • 2 in conversation