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!
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
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
Perfect, thank you so much!! Would have taken a long time for me to find that out on my own.
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!
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.