BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lillymaginta
Lapis Lazuli | Level 10

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
1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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

2 REPLIES 2
PGStats
Opal | Level 21

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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 2 replies
  • 937 views
  • 1 like
  • 2 in conversation