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

This is driving me crazy.  I need to put the variable into datetime format but I get January 1, 1960 when I do.  Here is the code:

data null;
format Current_Date mmddyy10. Today datetime20.;
Current_Date = today();
Today = today();
run;

This is the result:

Current_DateToday
08/11/202101Jan1960 6:15:03

Why am I getting the wrong date with the datetime format?

 

Thanks!

 

1 ACCEPTED SOLUTION

Accepted Solutions
jimbarbour
Meteorite | Level 14

Today() does not return a date-time value, it only returns a date.

 

Try this:

data null;
    format Current_Date mmddyy10. Today datetime20.;
    Current_Date = today();
    Today = datetime();
    PUTLOG "NOTE: " Current_Date= Today=;
run;

Jim

View solution in original post

5 REPLIES 5
jimbarbour
Meteorite | Level 14

Today() does not return a date-time value, it only returns a date.

 

Try this:

data null;
    format Current_Date mmddyy10. Today datetime20.;
    Current_Date = today();
    Today = datetime();
    PUTLOG "NOTE: " Current_Date= Today=;
run;

Jim

JHE
Obsidian | Level 7 JHE
Obsidian | Level 7

I have date is the forma such as : 8/21/2021,  customer need the format as : 2021/08/21, how do I ? 

JHE
Obsidian | Level 7 JHE
Obsidian | Level 7

I need convert date display:

 

I have date for example: 8/21/2021, customer need display this format as 2021/08/21.

 

What I could do? 

 

Thank you 

PaigeMiller
Diamond | Level 26

Use format date9. for variable TODAY, which is a date, not a date/time

 

or

 

use the DATETIME() function and use format datetime20.

--
Paige Miller
Tom
Super User Tom
Super User

Because you used the wrong format for the value you stored.  You stored the number of days since 1960 into the variable and are treating that (small) number as if it was the number of seconds since 1960.  Because the number of days  is so much smaller than the number of seconds (off by a factor of 24*60*60) it is showing as some time in the morning of the January first.

 

Remember that SAS datasets have two types of variables: fixed length characters strings and floating point numbers.  Formats are just instructions for how to convert values to text.  Informats are instructions for how to convert text into values.

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
  • 5 replies
  • 747 views
  • 8 likes
  • 5 in conversation