BookmarkSubscribeRSS Feed
DanD
Calcite | Level 5
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
4 REPLIES 4
DBailey
Lapis Lazuli | Level 10
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.
ChendhilKumar
Calcite | Level 5
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.


DanD
Calcite | Level 5
Thanks for the help. I did use this and it worked.
DanD
Calcite | Level 5
Thanks for the reply. It did work.
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
  • 1918 views
  • 0 likes
  • 3 in conversation