DATA Step, Macro, Functions and more

Re-coding to dates

Accepted Solution Solved
Reply
Contributor
Posts: 60
Accepted Solution

Re-coding to dates

I have a variable date with values month1-month38 and i want to recode them to 1/1/2012-1/1/2015. Is there an easy way to do this? Using array maybe?


Accepted Solutions
Solution
‎05-27-2015 11:08 AM
Super User
Posts: 11,343

Re: Re-coding to dates

If the current value is actually month1 then the current variable is text. Do you want an actual SAS date valued variable (recommended) or a text string.

If month1 represents Jan 2012 then something like:

newdate = intnx('Month','01JAN2012'd,(input(substr(date,6),best2.) -1),'BEGINNING');

FORMAT newdate mmddyy10.;

View solution in original post


All Replies
Solution
‎05-27-2015 11:08 AM
Super User
Posts: 11,343

Re: Re-coding to dates

If the current value is actually month1 then the current variable is text. Do you want an actual SAS date valued variable (recommended) or a text string.

If month1 represents Jan 2012 then something like:

newdate = intnx('Month','01JAN2012'd,(input(substr(date,6),best2.) -1),'BEGINNING');

FORMAT newdate mmddyy10.;

Contributor
Posts: 60

Re: Re-coding to dates

Thanks this is exactly what i was looking for!

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 182 views
  • 0 likes
  • 2 in conversation