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

How to read date from a txt file?

am trying to read this way.But saw some errors

File4.txt

1 arun joy 12/6/1989

data g;

infile 'H:\SasWorkSpace\File4.txt';

input no @2 name $9.  @12 dob   ddmmyy10.;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
Scott_Mitchell
Quartz | Level 8

Your informat was incorrect.  Try this.

data g;

infile 'e:\test\File4.txt';

input no @2 name $9.  @12 dob   ddmmyy9.;

format dob date9.;

run;

View solution in original post

4 REPLIES 4
Scott_Mitchell
Quartz | Level 8

Your informat was incorrect.  Try this.

data g;

infile 'e:\test\File4.txt';

input no @2 name $9.  @12 dob   ddmmyy9.;

format dob date9.;

run;

KrishnaChandra
Calcite | Level 5

Got output.Thank you so much for your valuable information.Am a beginner in SAS

Scott_Mitchell
Quartz | Level 8

We all have to start somewhere. We are here to help when we can.

cov_derek
Fluorite | Level 6

Krishna,

I would use a colon (:) modifier on the ddmmyy10. informat instead of changing the informat length.

data g;

infile  'e:\test\File4.txt';

format dob date9.;

run;

The colon basically allows SAS to stop processing as soon as it hits the space in position 10, and translate the string of 9 characters instead of expecting all 10. The problem with the simple solution of changing the format length is that if you have a date longer than that like 14/10/2014, only reading 9 characters will give you incorrect results.

Hope this helps your understanding,

Derek

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 7384 views
  • 1 like
  • 3 in conversation