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

Hi,

 

Below code when executed gives

**********

data ds_dtcon;
mydt='01/01/01';
mynumdt = input(mydt,ddmmyy10.);
format mynumdt ddmmyy10.;
run;

**********

Output

mydt = 01/01/01

mynumdt = 01/01/2001

**********

 

But the same code as shown below when executed with different date pattern it shows wrong date output.

data ds_dtcon1;
mydt='01/jan/2001';
mynumdt = input(mydt,date9.);
format mynumdt date9.;
run;

**********

Output

mydt = 01/jan/2001

mynumdt = 01JAN2020

**********

 

Any guidance is appreciated.

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

The problem lies here:

 

mynumdt = input(mydt, date9.);

 

The instruction "date9." tells SAS to read only 9 characters of MYDT.  It isn't reading the last two characters.  Switch to:

 

mynumdt = input(mydt, date11.);

 

Good luck.

View solution in original post

6 REPLIES 6
Astounding
PROC Star

The problem lies here:

 

mynumdt = input(mydt, date9.);

 

The instruction "date9." tells SAS to read only 9 characters of MYDT.  It isn't reading the last two characters.  Switch to:

 

mynumdt = input(mydt, date11.);

 

Good luck.

a_k93
Fluorite | Level 6

I got confused because of below code  where for Informat mydt date7. is mentioned and still it gives proper output.

 

data ds_conv;
input mydt;
informat mydt date7.;
format mydt date9.;
datalines;
10-Jan-2014
10-dec-2003
;
run;

 

ballardw
Super User

Input behaves differently with assigned informat, your example code, and informat in line.

Run this code and see what happens:

data work.ds_conv;
format mydt date9.;
input mydt date7.;
datalines;
10-Jan-2014
10-dec-2003
;
run;

Your original use of the input function with wrong value is like the above code not like the example that worked.

 

a_k93
Fluorite | Level 6

Thanks BallardW for the knowledge sharing and reply. The output shows ' . ' (period) incase of inline informat. I am newbie and learning, if possible can you share any links to read more on these topic.

FreelanceReinh
Jade | Level 19

Regarding the INPUT statement (as opposed to the INPUT function), I think it's most important to know the differences between list input and formatted input, which are two of the four different styles of reading raw data with the INPUT statement (the other two are called column input and named input, the latter being only rarely used, at least in my experience). These are described in the online documentation on the INPUT statement and in more detailed pages which are linked there.

The INFORMAT Statement can be used to perform so called modified list input (but there is another, I think more frequently used way to do this, see the above documentation on list input). This is explained in section "How SAS Treats Variables when You Assign Informats with the INFORMAT Statement" of the documentation on the INFORMAT Statement. There you find the explanation why you were able to read dates such as 10-Jan-2014 with the "too short" date7. informat in the INFORMAT statement: The width 7 is simply ignored in this case! (See third bullet point of that section.)

 

The INPUT function shares some features with formatted input (see above). In particular, specifying an informat with a sufficient length is important.

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1676 views
  • 0 likes
  • 4 in conversation