BookmarkSubscribeRSS Feed
KKJ
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(saslib.data)) %then %do;
%put blabla;
%end;
%else %do;
filename infil("&path.Textfile??????.txt");
data saslib.data;
length var1 8. var2 2. var3 2.;
infile infil dlm=':' firstobs = 2;
input var1 var2 var3;
run;
%end;
%mend files;
1 REPLY 1
sbb
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:

LoadDate = "&SYSDATE9:&SYSTIME"DT;

Scott Barry
SBBWorks, Inc.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 658 views
  • 0 likes
  • 2 in conversation