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.

sas-innovate-2024.png

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.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 940 views
  • 0 likes
  • 3 in conversation