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!

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 2 replies
  • 1156 views
  • 1 like
  • 2 in conversation