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
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.
@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?
num_date = input(substr(cats(char_date,'-01-01'),1,10),yymmdd10.);
Do this after reading your strings into a character variable of length 10.
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.