Desktop productivity for business analysts and programmers

Store text filenames from a windows directory in to a sas macro

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Store text filenames from a windows directory in to a sas macro

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


Accepted Solutions
Solution
3 weeks ago
Super User
Super User
Posts: 9,427

Re: Store text filenames from a windows directory in to a sas macro

Posted in reply to mayankdce1

What you want to use is sasautos:
http://documentation.sas.com/?docsetId=mcrolref&docsetTarget=p12b2qq72dkxpsn1e19y57emerr6.htm&docset...

 

There is no benefit to you coding this yourself.

View solution in original post


All Replies
Solution
3 weeks ago
Super User
Super User
Posts: 9,427

Re: Store text filenames from a windows directory in to a sas macro

Posted in reply to mayankdce1

What you want to use is sasautos:
http://documentation.sas.com/?docsetId=mcrolref&docsetTarget=p12b2qq72dkxpsn1e19y57emerr6.htm&docset...

 

There is no benefit to you coding this yourself.

New Contributor
Posts: 3

Re: Store text filenames from a windows directory in to a sas macro

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;
Super User
Super User
Posts: 9,427

Re: Store text filenames from a windows directory in to a sas macro

Posted in reply to mayankdce1

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.

New Contributor
Posts: 3

Re: Store text filenames from a windows directory in to a sas macro

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

 

☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 183 views
  • 4 likes
  • 2 in conversation