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!
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.