Learning SAS? Welcome to the exclusive online community for all SAS learners.

Changing the month or day in a date variable

Reply
Occasional Contributor
Posts: 6

Changing the month or day in a date variable

I have a dataset where if the month is missing in the date, I need to set it to 1 and if the day is missing i need to set it to 15. I am not sure how to approach it. I know how to check for the missing month or day but how do I set it to 1 or 15?

Super User
Posts: 19,772

Re: Changing the month or day in a date variable

Posted in reply to opoudyal0

You haven't given us enough information to help. Please post some example data of what you have and what you need. 

 

A SAS date is the number of days from Jan 1, 1960, but since you're missing components you likely have a text string. What that looks like is anyone's guess. 

 

SUBSTR can be used to replace text

and TRANSLATE/TRANSWRD 

 

The best solution is to create a SAS date so extract the parameters you do have and then use the replacement values in the ones you don't. 

 

MDY() will create a date. 

Ask a Question
Discussion stats
  • 1 reply
  • 190 views
  • 2 likes
  • 2 in conversation