BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
cactooos
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
PhilC
Rhodochrosite | Level 12

 

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

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

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.

cactooos
Obsidian | Level 7

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 ;
PhilC
Rhodochrosite | Level 12

 

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 11483 views
  • 4 likes
  • 3 in conversation