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_Date | Today |
08/11/2021 | 01Jan1960 6:15:03 |
Why am I getting the wrong date with the datetime format?
Thanks!
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
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
I have date is the forma such as : 8/21/2021, customer need the format as : 2021/08/21, how do I ?
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
Use format date9. for variable TODAY, which is a date, not a date/time
or
use the DATETIME() function and use format datetime20.
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.