Hi,
I am looking for a nicer way how to save date in the format MONDD. (like DEC29). I don't see this format build in and currently I am using concatenation of monname3. and day2.
Is there a simplier way for that for example by creating a bespoke format?
Thank you in advance,
Cheers
PROC FORMAT using PICTURE:
proc format;
picture mmmdd
low-high='%b%0d' (datatype=date);
run;
%macro RandBetween(min, max);
(&min + floor((1+&max-&min)*rand("uniform")))
%mend;
data want;
do i = 1 to 4;
date = %RandBetween("01Jan2019"d,"01Jan2020"d);
mmmdd = date;
format date mmddyy10.
mmmdd mmmdd. ;
output;
end;
run;
i date mmmdd 1 03/24/2019 MAR24 2 06/28/2019 JUN28 3 04/24/2019 APR24 4 08/20/2019 AUG20
This one comes close:
%put %sysfunc(today(),NLDATEMDM6.) ; Dec 29
But it leaves a space between the month and the date.
Also you can use the PICTURE statement in PROC FORMAT to generate your own custom format.
I am using this later as a variable name so would rather need DEC29 or DEC_29.
EDIT: Was not sure how to put the zero inside but found some solution, posting here if anyone search for MONDD.
proc format; picture mondd (default=5) other='%b%0d' (datatype=date); run; data _null_; call symputx( 'withzero', put(today()-21, mondd.)) ; run; %put &withzero ;
PROC FORMAT using PICTURE:
proc format;
picture mmmdd
low-high='%b%0d' (datatype=date);
run;
%macro RandBetween(min, max);
(&min + floor((1+&max-&min)*rand("uniform")))
%mend;
data want;
do i = 1 to 4;
date = %RandBetween("01Jan2019"d,"01Jan2020"d);
mmmdd = date;
format date mmddyy10.
mmmdd mmmdd. ;
output;
end;
run;
i date mmmdd 1 03/24/2019 MAR24 2 06/28/2019 JUN28 3 04/24/2019 APR24 4 08/20/2019 AUG20
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.