DATA Step, Macro, Functions and more

converting dates

Reply
Contributor
Posts: 32

converting dates

I have a file with a column in it and the date is in the format 01JAN2010. I need to convert the date to the format YYYYMM and then add 4 months to it. I found this code PUT(YEAR(nomination_ship_dt),4.)||PUT(MONTH(nomination_ship_dt),Z2.0) AS YEAR_MONTH LENGTH=6 FORMAT=$6. but in working with it I couldn't get it to work. I changed the format=$6 to format=6.0. I also tried removing the Length but I couldn't get it work. Any help is appreciated.

Thanks,

DanD
Super Contributor
Posts: 578

Re: converting dates

I would add the 4 months then convert. Adding 4 months would be
intnx('month',nomination_ship_dt,4) as new_ship_dt. My sas is down, but if you just need to format the new value, a custom format might be better.
Occasional Contributor
Posts: 7

Re: converting dates

data _null_;

attrib nomination_ship_dt informat=date9. format=date9.;
nomination_ship_dt='01jan2010'd;
put nomination_ship_dt=;

attrib next_ship_dt informat=date9. format=yymmn7.;
next_ship_dt=intnx('month', nomination_ship_dt, 4);
put next_ship_dt=;

run;

Log output:
nomination_ship_dt=01JAN2010
next_ship_dt=201005

Note: The above data step uses the YYMMxw. Format for next_ship_dt, where x is the separator. I have used N to indicates no separator.


Contributor
Posts: 32

Re: converting dates

Posted in reply to ChendhilKumar
Thanks for the help. I did use this and it worked.
Contributor
Posts: 32

Re: converting dates

Thanks for the reply. It did work.
Ask a Question
Discussion stats
  • 4 replies
  • 268 views
  • 0 likes
  • 3 in conversation