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
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;
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;
Thank you!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.