Hi. I am trying to pull the date out of a variable which contains underscores. The var contains just month and day so I need to add the current year and turn the var into a date (numeric) var. I tried to use scan and substr but since the month and day are not always in the same place (one digit day or two digit day) I could not get it to work.
This is what I start with:
Old_Date |
_12_Jul |
_4_Jul |
_1_Aug |
_5_Jan |
_12_Dec |
_1_Nov |
_10_Jul |
_28_Jul |
_5_Dec |
_7_Nov |
_9_Jul |
_28_Jul |
This is the desired output:
New_date |
07/12/14 |
07/04/14 |
08/01/14 |
01/05/14 |
12/12/14 |
11/01/14 |
07/10/14 |
07/28/14 |
12/05/14 |
11/07/14 |
07/09/14 |
07/28/14 |
data want;
set have;
day=compress(old_date,,'kd');
month=compress(old_date,,'ka');
new_date=input(cats(day,month,'2014'),date9.);
format new_date mmddyy10.;
run;
compress(old_date,'_'), then concat year to old date, followed by formatting.
Date=input(compress(old_date, '_')||'2014', date9.);
format date mmddyy10.;
Hi Thanks!. Your code didn't work I got back the error message: Invalid argument to function INPUT. Not sure why.
data want;
set have;
day=compress(old_date,,'kd');
month=compress(old_date,,'ka');
new_date=input(cats(day,month,'2014'),date9.);
format new_date mmddyy10.;
run;
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.