Help using Base SAS procedures

Why informat ignores the date length I define?

Reply
Occasional Contributor
Posts: 6

Why informat ignores the date length I define?

I tried to read the following data into SAS:

 

A.Jones       1-1-60         9-15-96      18JUN12
R.Grandage 03/18/1988 31-10-2007 5jul2012
K.Kaminaka 052903       2012024     12-MAR-12

 

data library;

infile 'C:\MyRawData\Library.dat' truncover;

informat name $10.;

informat birthday mmddyy6.;

informat issued anydtdte5.;

informat returned anydtdte5.;

input name $ +1 birthday +1 issueddate + 1 returneddate;

format returned date9.;

run;

 

You can see in the informat I defined the length of the dates are way less than the actual date legnth. But SAS is still reading the data fine. Can anyone explain why? Thanks!

Super User
Posts: 9,681

Re: Why informat ignores the date length I define?

Not test .Can you try:

 

 

data library;

infile 'C:\MyRawData\Library.dat' truncover dlm=' '; /*need specify delimiter here*/

 

input name : $10.  birthday : mmddyy6. issueddate : anydtdte5. returneddate : anydtdte5.;

format returned date9.;

run;

Super User
Super User
Posts: 6,500

Re: Why informat ignores the date length I define?

Mainly because you are using a LIST mode INPUT statement. That is what it does. It skips over the extra spaces.

If you want it to only input exactly the format you specified then you need to use a FORMATTED mode INPUT statement.

 

Also why did you include cursor movement commands +1 ?  

That could potentially move the cursor past the first character of the next value.  So it could read '11JAN2016' as '1JAN2016'.

 

 

 

Super User
Posts: 10,500

Re: Why informat ignores the date length I define?

I disbelieve that issuedate and returneddate were read correctly. You specified different variable names for  informat statements.

And with the corrected names the valus for issuedate and returneddate are not correct for the second record because of the +1.

Ask a Question
Discussion stats
  • 3 replies
  • 199 views
  • 0 likes
  • 4 in conversation