I am using the datastep to read in a text file. Each text file has a distinct filename. I'm unsure how to bring the distinct filename for each record into the table?
Here is my code:
libname YOKOGAWA "D:\***\*****\****\YOKOGAWA";
FILENAME NORM 1 \\**\***\SAS DATA NORMALIZER 1\NORMALIZER 1*.txt ;
data YOKOGAWA.NORM_1_YOKOGAWA
%let _EFIERR_ = 0; /*set the ERROR detection macro variable/*
infile NORM1 delimiter = ',' MISSOVER DSD lcrecl=32767
firstobs=20 EOV=SKIP;
informat yok_dttm ANYDTDTM23.;
informat fpm best32.;
input @; /*if skip then skip=0; else do; */
if skip then do;
skip=0;
input #19;
end;
else do;
input
yok_dttm
fpm
;
output;
end;
if _ERROR_ then call symputx('_EFIERR_',1);
RUN;
On the infile statement add:
FileName= TempFileName
This add a temporary variable that can be referenced but is not kept in the data set.
and in the body of the code
File = TempFileName;
this keeps the name of the file.
On the infile statement add:
FileName= TempFileName
This add a temporary variable that can be referenced but is not kept in the data set.
and in the body of the code
File = TempFileName;
this keeps the name of the file.
One more question,
The filename includes the whole directory which is over 70 characters long. The results only display the first 8 characters. I tried using the informat to bring in all characters, but it does not work. Ideally, I would like to use something like the substr function and only display the last few characters of the filename.
Forgot to mention that you need to specify the length of the file variable before use
length file $ 70;
Ok, I lied that wasn't my last question
I have added
infile filename = tempfilename;
length file $70.;
file=tempfilename;
In the log it lists the whole directory as the filename now. However, in the sas dataset file is only showing 8 characters. I tried adding "file" to the informat and format statements with 70 characters, but no success. What am I missing?
Sorry found what I was missing.
I was missing the length for tempfilename.
Thanks you so much for your help.
Lori
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.
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.