BookmarkSubscribeRSS Feed
metallon
Pyrite | Level 9

Hello SAS Experts,

 

Is there a way to read the file name acutally processed and put it in the first column of the dataset?

 

data Import_Import;
infile datalines;
length fil2read $40;
input fil2read $;
infile dummy filevar=fil2read end=done DSD
        DLM=';';
do while(not done);
INPUT
            A               : $CHAR11.
            B               : $CHAR11.
            C               : $CHAR11.
            D               : $CHAR100.
            E               : $CHAR96.
            F               : $CHAR1.
            G               : $CHAR6.
            H               : $CHAR2.
            I               : ?? COMMAX4.
            J              : $CHAR11.
            K              : $CHAR2.
            L              : ?? YYMMDD10.
            M              : $CHAR17.
            N              : $CHAR4.
            O              : $CHAR1.
            P              : $CHAR4.
            Q              : $CHAR1.
            R              : $CHAR1.
            S              : $CHAR4.
            T              : $CHAR1.
            U              : $CHAR1.
            V              : $CHAR1.
            W              : $CHAR1.
            X              : $CHAR4.
            Y              : $CHAR1.
            Z              : $CHAR1. ;
  output;
end;
datalines;
'C:\Users\x\test\H20154.csv'
'C:\Users\x\test\H20154.csv'
'C:\Users\x\test\B20154.csv'
'C:\Users\x\test\H20154.csv'
'C:\Users\x\test\N20154.csv'
;

2 REPLIES 2
Reeza
Super User

Use the FILENAME option in the infile statement. You should also make sure it's long enough to hold the path.

 

 

length filename $256.;

infile dummy filevar=fil2read filename=filename end=done DSD
        DLM=';';

source=filename;

 

This post may be of interest to you, especially if you have header rows in your files.

 

https://communities.sas.com/t5/SAS-Communities-Library/How-do-I-write-a-macro-to-import-multiple-tex...

ballardw
Super User

You were almost there. Since the FILEVAR is a temporary variable you need to assign it to a datastep variable.

data Import_Import;
   length ReadFile $ 40.;
   infile datalines;
   length fil2read $40;
   input fil2read $;
   infile dummy filevar=fil2read end=done DSD
        DLM=';';
   ReadFile = Fil2read;
   do while ..

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
  • 2 replies
  • 4418 views
  • 0 likes
  • 3 in conversation