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

I am testing on conversion of string to date with the following code:

 

%sysmstoreclear;

data test2;
dt1="05/DEC/2019";
dt2="30/SEP/2020";
dt3="05/dec/2020";
num1=input(dt1,date9.);
num2=input(dt2,date9.);
num3=input(dt3,date9.);
run;

 

the result is shown in the below picture, num1 and num3 have same value. Can anyone please advise what is the reason caused this?date9.jpg 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @tinaz5012 and welcome to the SAS Support Communities!

 

The date9. informat reads only the first 9 characters of the strings dt1, dt2, dt3, e.g., "05/DEC/2019" (i.e., 5th December 2020). Use the date11. informat to read all 11 characters.

View solution in original post

4 REPLIES 4
FreelanceReinh
Jade | Level 19

Hello @tinaz5012 and welcome to the SAS Support Communities!

 

The date9. informat reads only the first 9 characters of the strings dt1, dt2, dt3, e.g., "05/DEC/2019" (i.e., 5th December 2020). Use the date11. informat to read all 11 characters.

Reeza
Super User
That isn't a date9 format so it's getting garbled, date9 doesn't have separators. So SAS is reading only the 20 portion, the fact that the last two work correctly is just a coincidence.

Date11 will work fine.
juanormelli
Calcite | Level 5
data test2;
  dt1="05/DEC/2019";
  dt2="30/SEP/2020";
  dt3="05/dec/2020";
dt4="30/SEP/2021"; num1=input(dt1,date11.); num2=input(dt2,date11.); num3=input(dt3,date11.); Num4=input(dt4,date11.); format num1 num2 num3 num4 MONYY.; run;

 

the date9 format. take only the first nine numbers of the date to get them all use the date11., according to the code below I used Format to debug and show that date11. really is it works.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 623 views
  • 1 like
  • 4 in conversation