BookmarkSubscribeRSS Feed
HitmonTran
Pyrite | Level 9

Hi,

I have a date variable (character) and I want to convert it to numeric date value.  however, there are some dates missing day and month.  Is there a format I can easily use along with input function?

 

current in character format:

2009-10-14
2010-12-24
2001-03
2006-06
2012
2002-03-27
2003-02-03
 

 

 


I want  same values but in numeric date:

2009-10-14
2010-12-24
2001-03 
2006-06 
2012 
2002-03-27
2003-02-03

 

 
4 REPLIES 4
PaigeMiller
Diamond | Level 26

The only way I know of that makes sense, is if the day is missing, assign it to 1. If the month is missing, assign it to January. Then all of your records now have a year/month/day, and you can assign a format to them. If necessary, you can also created "flag" variables to indicate if the day was missing or to indicate if the month was missing.

--
Paige Miller
HitmonTran
Pyrite | Level 9
yes, that's how I would normally impute dates but this analysis is not requiring date imputation but I still need a numeric value that is equivalent.
PaigeMiller
Diamond | Level 26

@HitmonTran wrote:
yes, that's how I would normally impute dates but this analysis is not requiring date imputation but I still need a numeric value that is equivalent.

Can you explain further? What are you going to do with this data, where you must work with some calendar information that has no day and some calendar information that has no month?

--
Paige Miller

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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 lock in 2025 pricing—just $495!

Register now

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
  • 4 replies
  • 2582 views
  • 3 likes
  • 3 in conversation