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

Dear all,

 

I am looking for the way to convert character date value to numeric date value like below shown

Capture2.PNG

What I wanted is to have TO_DATE from 22/04/2023 in numeric form transferred to 22APR2023 in numeric form.

 

here is my code attempt to do so but failed. any suggestion would you advice to me? 

 

DATA mydata4;
SET mydata3;

FROM_DATE2=input(FROM_DATE,DDMMYY10.);
TO_DATE2=input(TO_DATE,DDMMYY10.);

FROM_DATE3=put(FROM_DATE2,DATE9.);
TO_DATE3=put(TO_DATE2,DATE9.);

RUN;

 

Thanks in advance.

 

regards,

Harry

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

22/04/2023 in "numeric" form is twenty-two divided by four divided by two thousand and twenty-three and so has nothing to with a date value.

 

The number in your PICTURE looks to be 23,122 (twenty-three thousand one hundred and twenty-two).

 

If you want that number to PRINT as 22APR2023 then just print it using the DATE9. format.

1591  data test;
1592   to_date=23122;
1593   put to_date date9.;
1594  run;

22APR2023

Try something like this to see the impact of using different formats to display the same number.

DATA mydata4;
  SET mydata3;
  from_date2=from_date;
  from_date3=from_date;
  from_date4=from_date;
  format from_date comma6. from_date2 ddmmyy10. from_date3 date9. from_date4 yymmdd10.;
run;

PS Displaying dates in either DMY or MDY order will confuse half of your audience.

View solution in original post

1 REPLY 1
Tom
Super User Tom
Super User

22/04/2023 in "numeric" form is twenty-two divided by four divided by two thousand and twenty-three and so has nothing to with a date value.

 

The number in your PICTURE looks to be 23,122 (twenty-three thousand one hundred and twenty-two).

 

If you want that number to PRINT as 22APR2023 then just print it using the DATE9. format.

1591  data test;
1592   to_date=23122;
1593   put to_date date9.;
1594  run;

22APR2023

Try something like this to see the impact of using different formats to display the same number.

DATA mydata4;
  SET mydata3;
  from_date2=from_date;
  from_date3=from_date;
  from_date4=from_date;
  format from_date comma6. from_date2 ddmmyy10. from_date3 date9. from_date4 yymmdd10.;
run;

PS Displaying dates in either DMY or MDY order will confuse half of your audience.

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
  • 1 reply
  • 262 views
  • 1 like
  • 2 in conversation