BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
NewUsrStat
Pyrite | Level 9

Hi guys, 

I'm trying to set an interval of time of 1 month from a starting date (named "admission" in the original dataset).

Starting dates are for example: 01JAN2017, 01FEB2017, 01MAR2017 etc. 

I'm using the following code: 

 

data data; 
	set mydataset; 
	discharge  = INTNX('month', admission, +1);
	format discharge date9.;
run;

The following output is generated: 

01JAN2017 01FEB2017

01FEB2017 01MAR2017

01MAR2017 01APR2017

.....................  ......................

 

Is there a way to prevent the start-ending day is the same? In other words I would like to prevent that for example 01FEB2017 appears two times: one as ending day of an interval and the other as the starting day of the subsequent interval. This because I'm counting observation and if the same day is reported two times it is difficult to assign observations to the previous or subsequent month. 

 

Is there a way to prevent this? It is ok if the month ends with 28-29 (FEB) or 30-31 and the starting day is always the first day of the month. 

 

Thank you in advance

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
antonbcristina
SAS Employee

An easy solution would be to subtract 1 from the discharge date calculated. This will give you the previous day as the discharge date and eliminate overlap of date ranges.  

View solution in original post

2 REPLIES 2
antonbcristina
SAS Employee

An easy solution would be to subtract 1 from the discharge date calculated. This will give you the previous day as the discharge date and eliminate overlap of date ranges.  

ballardw
Super User

I'm not sure I understand what your actual requirement may be because there is nothing creating an admission date that forces correspondence to the beginning of a month that you indicate you may be creating.

 

The INTNX function does have an ALIGNMENT parameter to get the start or end of an interval or try to get the same point in the increment.

So test this:

data data; 
	set mydataset; 
	endofmonth  = INTNX('month', admission, 0,'E');
        samedaynextmoth = intnx('month',admission,1,'S');
        midnextmonth  = intnx('month', admission,1,'M')
        ;
	format endofmonth samedaynextmonth midnextmonth date9.;
run;

E is END, S is SAME , M is Middle, B is Beginning and the default. So your code was generating the Beginning of the next moth.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 575 views
  • 3 likes
  • 3 in conversation