BookmarkSubscribeRSS Feed
Calcite | Level 5 KKJ
Calcite | Level 5
Hello!! I´ve made this macro to import several txt files to a dataset. What i also would like to do is to save each imported txt files name into a new dataset? I´ve got no clue how i would go about this. can someone push me in the right direction? Thanks

%macro files();
%if %sysfunc(exist( %then %do;
%put blabla;
%else %do;
filename infil("&path.Textfile??????.txt");
length var1 8. var2 2. var3 2.;
infile infil dlm=':' firstobs = 2;
input var1 var2 var3;
%mend files;
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
You can use a RETAIN statement or a SAS assignment statement to create some SAS DATA step variable with your file name. Then on subsequent executions (not sure what you intend here), you can concatenate your permanent-named file from some LIBNAME location and add new observations as you process new input files. You will likely use the SAS EXIST function to test whether the permanent file you use for tracking already exists. Also, you can use a SAS assignment statement and a macro variable to create a new observation -- use an ATTRIB or LENGTH to establish a SAS CHARACTER variable, such as:

FileName = "&path\&whatever_macro_var_you_use";

Depending on the level of importance with this data, consider making a backup copy of the tracking file in case you have to do a restore/recovery. And you may want to add a SAS DATETIME variable (using an ATTRIB with an appropriate FORMAT) to go along with the FileName variable, such as:


Scott Barry
SBBWorks, Inc.


Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.


Register now!

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
  • 1 reply
  • 2 in conversation