BookmarkSubscribeRSS Feed
Anita_n
Pyrite | Level 9

Hello,

is there any thing like day month or month day formats like the MMYYw. 

Am looking for something like DDMMw. or MMDDw.

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

How about

 

data _null_;
   dt = today();
   put dt = mmddyy4.;
run
ballardw
Super User

@Anita_n wrote:

Hello,

is there any thing like day month or month day formats like the MMYYw. 

Am looking for something like DDMMw. or MMDDw.


If you find that you cannot get what you want with any of the existing SAS formats you can use Proc Format with the Picture statement to create one of your own for dates, times or date times.

 

You get an MMDD using the MMDDYY4. but an example for DDMM

proc format;
picture ddmm
low-high ='%0D%0m' (datatype=date)
;
run;

data example;
  date=today();
run;

proc print data=example;
   format date ddmm.;
run;

The directives in the Picture statement, those things with %, are used to indicate the specific part of a date, time or datetime value. They are very case sensitive: %m is month, %M is minute . You want to use single quotes to avoid messages from the macro processor. The 0 forces always showing 2 digits for month and day with 01 to 09.  Other characters in the picture are displayed literally. The datatype is used to tell SAS which type of value is expected so the directives are applied correctly when the value type matches.

Anita_n
Pyrite | Level 9

@ballardw @PeterClemmensen  Thanks for that, it's amazing what one can learn from you guys.  I realised I did not explain my question correctly. What I really wanted is , if I have two date variables and I find for example the difference between the dates in days 

data have;
format date1 date2 ddmmyy10.;
date1='30dec2000'd;
date2=today();
var3=intck("day",date1, date2);
run;
*var3 should be displayed like 10months 5days or 2years 6months 5days;

I used day here because some results are less than 30days and might be displayed as 0. I want the the result of var3 to display the above results in days if the value of var3 is less than 30  but if the value is above 30, it should display something like 1month 3days, 12months 15days ......................

 

I don't really know if this is possible.  This is to avoid having values like 11555 days, where the reader will first have to convert it to months. I will appreciate any help

ballardw
Super User

Use case for verbiage like 1 month, 3 days? By use case I mean "how is this value to actually be used in other processes"?

 

Since your example dates of 30Dec2000 and today, 08Mar2023 or so, means there are about 267 months why is that of much use? People still need to convert that to something like years/months/days to make much sense.

 


@Anita_n wrote:

@ballardw @PeterClemmensen  Thanks for that, it's amazing what one can learn from you guys.  I realised I did not explain my question correctly. What I really wanted is , if I have two date variables and I find for example the difference between the dates in days 

data have;
format date1 date2 ddmmyy10.;
date1='30dec2000'd;
date2=today();
var3=intck("day",date1, date2);
run;
*var3 should be displayed like 10months 5days or 2years 6months 5days;

I used day here because some results are less than 30days and might be displayed as 0. I want the the result of var3 to display the above results in days if the value of var3 is less than 30  but if the value is above 30, it should display something like 1month 3days, 12months 15days ......................

 

I don't really know if this is possible.  This is to avoid having values like 11555 days, where the reader will first have to convert it to months. I will appreciate any help


 

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 755 views
  • 2 likes
  • 3 in conversation