DATA Step, Macro, Functions and more

finding observations in the month before a specific date

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 128
Accepted Solution

finding observations in the month before a specific date

I am trying to summarize observations that occur in the month prior to specific date and create another summary to observations that occurred two months before the same date and so on.  

id proc_date  proc_type   hosp_date 
1     11/13/2005   a              12/1/2005
1      10/13/2005  a              12/1/2005 
2       2/3/2004     b               3/1/2004
2       1/14/2004   c                3/1/2004

 each id has one hosp_day but multiple proc_date. 

The output I am looking is 

during 1 months pre hosp_date would include;

id proc_date  proc_type   hosp_date 
1     11/13/2005   a              12/1/2005
2       2/3/2004     b               3/1/2004

during the 2 months pre hosp_dae would include: 

id proc_date  proc_type   hosp_date 
1      10/13/2005  a              12/1/2005 
2       1/14/2004   c                3/1/2004

Accepted Solutions
Solution
‎10-18-2016 04:56 PM
Respected Advisor
Posts: 4,927

Re: finding observations in the month before a specific date

Posted in reply to lillymaginta

Use function INTCK with option "CONTINUOUS" to get the number of months :

 

data want;
set have;
months = intck("MONTH", proc_date, hosp_date, "CONTINUOUS");
run;

proc sort data=want; by months id proc_date; run;

proc print data=want; 
by months; id months;
var id proc_date  proc_type   hosp_date;
run;
PG

View solution in original post


All Replies
Solution
‎10-18-2016 04:56 PM
Respected Advisor
Posts: 4,927

Re: finding observations in the month before a specific date

Posted in reply to lillymaginta

Use function INTCK with option "CONTINUOUS" to get the number of months :

 

data want;
set have;
months = intck("MONTH", proc_date, hosp_date, "CONTINUOUS");
run;

proc sort data=want; by months id proc_date; run;

proc print data=want; 
by months; id months;
var id proc_date  proc_type   hosp_date;
run;
PG
Frequent Contributor
Posts: 128

Re: finding observations in the month before a specific date

Thank you! 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 195 views
  • 1 like
  • 2 in conversation