MONTH-YY and MON-YY date format?

Accepted Solution Solved
Reply
Contributor sm4
Contributor
Posts: 51
Accepted Solution

MONTH-YY and MON-YY date format?

This seems like a really basic question that I should find in documentation or on a previous post, but somehow I haven't been able to.

 

If I have a sas date like 01NOV2017, how do I format it so that it shows up as November-17 or Nov-17 (with dash delimiter)?

Doesn't seem like either of these options are offered by SAS, though there are others like DDMMYYx with delimiters...is it possible to create a custom format to address the issue?

 

Would appreciate any tips....thank you!


Accepted Solutions
Solution
‎03-19-2018 09:36 AM
Super User
Super User
Posts: 8,127

Re: MONTH-YY and MON-YY date format?

You can use MONYY format to get it without the Hyphen.

Otherwise roll you own.

proc format ;
picture monyyd (default=8)
 low - high = '%b-%Y' (datatype=date)
;
picture monthyyd (default=14)
 low - high = '%B-%Y' (datatype=date)
;
run;
data _null_;
 do month=1 to 12 ;
   date=mdy(month,1,2017);
   put date= date9. +1 date monyy. +1 date monyyd. +1 date monthyyd. +1 date monthyyd.-l;
 end;
run;
date=01JAN2017  JAN17 JAN-2017   January-2017 January-2017
date=01FEB2017  FEB17 FEB-2017  February-2017 February-2017
date=01MAR2017  MAR17 MAR-2017     March-2017 March-2017
date=01APR2017  APR17 APR-2017     April-2017 April-2017
date=01MAY2017  MAY17 MAY-2017       May-2017 May-2017
date=01JUN2017  JUN17 JUN-2017      June-2017 June-2017
date=01JUL2017  JUL17 JUL-2017      July-2017 July-2017
date=01AUG2017  AUG17 AUG-2017    August-2017 August-2017
date=01SEP2017  SEP17 SEP-2017 September-2017 September-2017
date=01OCT2017  OCT17 OCT-2017   October-2017 October-2017
date=01NOV2017  NOV17 NOV-2017  November-2017 November-2017
date=01DEC2017  DEC17 DEC-2017  December-2017 December-2017

View solution in original post


All Replies
Solution
‎03-19-2018 09:36 AM
Super User
Super User
Posts: 8,127

Re: MONTH-YY and MON-YY date format?

You can use MONYY format to get it without the Hyphen.

Otherwise roll you own.

proc format ;
picture monyyd (default=8)
 low - high = '%b-%Y' (datatype=date)
;
picture monthyyd (default=14)
 low - high = '%B-%Y' (datatype=date)
;
run;
data _null_;
 do month=1 to 12 ;
   date=mdy(month,1,2017);
   put date= date9. +1 date monyy. +1 date monyyd. +1 date monthyyd. +1 date monthyyd.-l;
 end;
run;
date=01JAN2017  JAN17 JAN-2017   January-2017 January-2017
date=01FEB2017  FEB17 FEB-2017  February-2017 February-2017
date=01MAR2017  MAR17 MAR-2017     March-2017 March-2017
date=01APR2017  APR17 APR-2017     April-2017 April-2017
date=01MAY2017  MAY17 MAY-2017       May-2017 May-2017
date=01JUN2017  JUN17 JUN-2017      June-2017 June-2017
date=01JUL2017  JUL17 JUL-2017      July-2017 July-2017
date=01AUG2017  AUG17 AUG-2017    August-2017 August-2017
date=01SEP2017  SEP17 SEP-2017 September-2017 September-2017
date=01OCT2017  OCT17 OCT-2017   October-2017 October-2017
date=01NOV2017  NOV17 NOV-2017  November-2017 November-2017
date=01DEC2017  DEC17 DEC-2017  December-2017 December-2017
Contributor sm4
Contributor
Posts: 51

Re: MONTH-YY and MON-YY date format?

Perfect, thank you so much!! Would have taken a long time for me to find that out on my own.

Contributor sm4
Contributor
Posts: 51

Re: MONTH-YY and MON-YY date format?

After playing with this I actually have a follow-up question: 
Looks like picture formats may not work in sgplot: https://communities.sas.com/t5/SAS-GRAPH-and-ODS-Graphics/Picture-Formats-Not-Rendered-in-PROC-SGPLO.... Do you happen to know of any other method? Should have mentioned that one of my outputs is a graph.

 

 

Still really helpful for other outputs I'm doing, though. Thanks a bunch!

 

 

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 351 views
  • 6 likes
  • 2 in conversation