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

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!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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!

 


 

View solution in original post

2 REPLIES 2
Reeza
Super User

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!

 


 

Orchidn
Fluorite | Level 6
Hi Reeza,

Thank you so much for your prompt and useful response!
This is great!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1573 views
  • 1 like
  • 2 in conversation