BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
LAtwood
Calcite | Level 5

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;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

5 REPLIES 5
ballardw
Super User

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.

LAtwood
Calcite | Level 5

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.

ballardw
Super User

Forgot to mention that you need to specify the length of the file variable before use

length file $ 70;

LAtwood
Calcite | Level 5

Ok, I lied that wasn't my last question Smiley Happy


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?

LAtwood
Calcite | Level 5

Sorry found what I was missing.

I was missing the length for tempfilename.

Thanks you so much for your help.

Lori

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