Hi everyone,
I have a record which has a missing value for a datetime20. field called ReportingDate.
I would like to replace the missing value with a constant - like this '23Jan2021'd.
If I assign this:
if ReportingDate=. then ReportingDate= '23Jan2021'd
I obtain this value: 01JAN1960:06:11:43 instead of the 23Jan2021 value that I want.
How can I solve this issue?
Thank you so much!
You've provided a date, not a DATETIME value.
You can use the DHMS function and pass the date in as the number of days to get a DateTime variable, or you can provide it as a datetime literal.
if ReportingDate=. then ReportingDate= dhms('23Jan2021'd, 0, 0, 0);
if ReportingDate=. then ReportingDate= '23Jan2021:00:00:00'dt;
Here's a great, but longer and in depth, reference for dates and times in SAS
https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/...
@Orchidn wrote:
Hi everyone,
I have a record which has a missing value for a datetime20. field called ReportingDate.
I would like to replace the missing value with a constant - like this '23Jan2021'd.
If I assign this:
if ReportingDate=. then ReportingDate= '23Jan2021'd
I obtain this value: 01JAN1960:06:11:43 instead of the 23Jan2021 value that I want.
How can I solve this issue?
Thank you so much!
You've provided a date, not a DATETIME value.
You can use the DHMS function and pass the date in as the number of days to get a DateTime variable, or you can provide it as a datetime literal.
if ReportingDate=. then ReportingDate= dhms('23Jan2021'd, 0, 0, 0);
if ReportingDate=. then ReportingDate= '23Jan2021:00:00:00'dt;
Here's a great, but longer and in depth, reference for dates and times in SAS
https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/...
@Orchidn wrote:
Hi everyone,
I have a record which has a missing value for a datetime20. field called ReportingDate.
I would like to replace the missing value with a constant - like this '23Jan2021'd.
If I assign this:
if ReportingDate=. then ReportingDate= '23Jan2021'd
I obtain this value: 01JAN1960:06:11:43 instead of the 23Jan2021 value that I want.
How can I solve this issue?
Thank you so much!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.