BookmarkSubscribeRSS Feed
elhuda
Calcite | Level 5


I would like to use all of the text files from a directory as multiple sources for a SAS DI job.  I know how to do this in code using a filename statement piping out to a directory, creating a SAS dataset from this file and using a macro (excuse the syntax):

data dirlist;

infile "pipedfile"

run;

%macro readwrite(filename)

data dynamicsasname;

infile "filename";

run;

%mend;

data _null_:

set dirlist;

call execute(%readwrite(filename))

run;

How can I do this in DI using the GUI interface?

3 REPLIES 3
LinusH
Tourmaline | Level 20

First create a job thar reads the input file, use a parameter for the filename.

Then build an "outer job" with the Loop transform, and using your "pipedfile"/dirlist as input.

Put you first job within the Loop, and map your input dirlist to the job parameter.

This will make the inner job run as many times as there are records in the parameter table, and your parameter will resolve as different macro variable values for each iteration.

See the online doc/help, there are some step-by-step guides on how to build this...

Data never sleeps
forumsguy
Fluorite | Level 6

Yes .. Even I have used the same technique suggested by Linus in my previous organization. It always works

Patrick
Opal | Level 21

Is this Windows or Unix?

If there is some naming pattern to your files then you could use a wildcard in the file name of the external file, eg: ....\folder\myfiles_*.dat

This will translate into SAS code like: infile "....\folder\myfiles_*.dat" which is valid syntax and will read all files matching the pattern.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 2719 views
  • 0 likes
  • 4 in conversation