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.

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

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