BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Mgarret
Obsidian | Level 7

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
1 ACCEPTED SOLUTION

Accepted Solutions
stat_sas
Ammonite | Level 13

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;

View solution in original post

4 REPLIES 4
venka
Calcite | Level 5

compress(old_date,'_'), then concat year to old date, followed by formatting.

Reeza
Super User

Date=input(compress(old_date, '_')||'2014', date9.);

format date mmddyy10.;

Mgarret
Obsidian | Level 7

Hi Thanks!.  Your code didn't work I got back the error message:   Invalid argument to function INPUT.  Not sure why.

stat_sas
Ammonite | Level 13

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;

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
  • 1422 views
  • 0 likes
  • 4 in conversation