How to read date from a txt file?

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 89
Accepted Solution

How to read date from a txt file?

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;


Accepted Solutions
Solution
‎07-10-2014 03:06 AM
Super Contributor
Posts: 297

Re: How to read date from a txt file?

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


All Replies
Solution
‎07-10-2014 03:06 AM
Super Contributor
Posts: 297

Re: How to read date from a txt file?

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;

Frequent Contributor
Posts: 89

Re: How to read date from a txt file?

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

Super Contributor
Posts: 297

Re: How to read date from a txt file?

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

Contributor
Posts: 23

Re: How to read date from a txt file?

Krishna,

I would use a colon (Smiley Happy 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

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 1167 views
  • 1 like
  • 3 in conversation