I want to calculate surgeon volume before 365 days of an index operation on a subject.
I have records for a service user, service date and surgeon ID
data WORK.docs_have(label='Surgery Data'); input rcpt_id:32. service_date:date9. physician_id:32.; format service_date date9.; datalines; 1356 22NOV2008 3354 1123 13OCT2010 3354 1267 18JAN2011 3354 1123 15AUG2011 3354 1145 30NOV2009 2234 1323 24JAN2010 2234 1122 29JAN2010 2234 1122 13SEP2010 2234 ;;;;
and I want Output like this
data WORK.docs_want(label='Surgery Data_want'); input rcpt_id:32. service_date:date9. physician_id:32. surg_vol:12; format service_date date9.; datalines; 1356 22NOV2008 3354 0 1123 13OCT2010 3354 0 1267 18JAN2011 3354 1 1123 15AUG2011 3354 2 1145 30NOV2009 2234 0 1323 24JAN2010 2234 1 1122 29JAN2010 2234 2 ;;;;
Below is an example of how to do something very close to what you want. I'm using calendar year in this example, but I believe you want a 365 day period not just calendar year. You would need to modify my example if calendar year is not what you want, but the solution should be along the lines of what I have coded.
Jim
data WORK.docs_have(label='Surgery Data');
input rcpt_id:32. service_date:date9. physician_id:32.;
format service_date date9.;
datalines;
1356 22NOV2008 3354
1123 13OCT2010 3354
1267 18JAN2011 3354
1123 15AUG2011 3354
1145 30NOV2009 2234
1323 24JAN2010 2234
1122 29JAN2010 2234
1122 13SEP2010 2234
;;;;
run;
PROC SQL;
CREATE TABLE WORK.Surgery_Volume AS
SELECT Physician_ID
, YEAR(Service_Date) AS Year
,COUNT(YEAR(Service_Date)) AS Total_Vol
FROM WORK.Docs_Have
GROUP BY Physician_ID, Year
;
QUIT;
PROC SQL;
CREATE TABLE WORK.Docs_Vol AS
SELECT Rcpt_ID
,Service_Date
,Docs.Physician_ID
,Year
,Total_Vol
FROM WORK.Docs_Have Docs
INNER JOIN WORK.Surgery_Volume Surg
ON Docs.Physician_ID = Surg.Physician_ID
AND YEAR(Service_Date) = Year
;
QUIT;
PROC SORT DATA=WORK.Docs_Vol;
BY Physician_ID Year Total_Vol;
QUIT;
DATA WORK.Docs_Want;
DROP Year
Total_Vol
;
SET WORK.Docs_Vol;
BY Physician_ID Year Total_Vol;
IF Total_Vol > 1 THEN
DO;
IF FIRST.Total_Vol THEN
Surg_Vol = 1;
ELSE
Surg_Vol + 1;
END;
ELSE
DO;
Surg_Vol = 0;
END;
RUN;
Results:
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.