I'm testing a case definition that's looking for patients who have at least 3 separate healthcare visits during the year, and all 3 visits have to be at least 30 days apart. Each visit is stored in a separate record. So a person who had 6 visits during the year would have 6 records in the file.
I tested a similar definition, but it only required 2 visits. I accomplished that by doing a PROC SQL join that merged the data file with itself. This created a many-to-many merge. Then it was just a matter of finding all records where the difference in dates was 30 days or more, flagging them, and selecting all people who had at least one flag. But when I tried this approach with 3 dates, the file created by the many-to-many-to-many merge was too big and took too long to create to be practical.
I should also note that I need to calculate true positives, false positives, true negatives, false negatives, sensitivity, and specificity. So I can't simply drop cases that don't fit the criteria, because those cases will need to be classified later. Instead, all cases have to be flagged to indicate if they qualify for the definition or not.
Here is the code I used for the 2-visit version:
/*Create A and B versions of claim file, use PROC SQL to create a many-to-many merge. This will generate
a file with all possible combinations of claims dates.*/
PROC SQL;
Create Table temp.SCA_ICD10_def&defnumb._mm
as Select a.encrypted_id, a.Med_def1516171920_count,
a.DxSCA1520_max as DxSCA1520_max_A,
b.DxSCA1520_max as DxSCA1520_max_B,
a.CLAIM_SERVICE_FROM_DATE as CLAIM_DATE_A,
b.CLAIM_SERVICE_FROM_DATE as CLAIM_DATE_B
From temp.SCA_ICD10_def&defnumb._line_rec as a JOIN temp.SCA_ICD10_def&defnumb._line_rec as b
ON a.encrypted_id = b.encrypted_id
order by a.encrypted_id, a.CLAIM_SERVICE_FROM_DATE;
QUIT;
/****Apply Case Definition &defnumb. - At least 2 visits at least 30 days apart****/
DATA temp.SCA_ICD10_def&defnumb._dates; SET temp.SCA_ICD10_def&defnumb._mm;
/*Convert claim dates to raw numbers so number of days will calculate correctly even across months*/
CLAIM_DATE_A_n=input(put(CLAIM_DATE_A,yymmddn8.), 8.);
CLAIM_DATE_B_n=input(put(CLAIM_DATE_B,yymmddn8.), 8.);
CLAIM_DATE_A_n2=input(put(CLAIM_DATE_A_n,$8.),yymmdd8.);
CLAIM_DATE_B_n2=input(put(CLAIM_DATE_B_n,$8.),yymmdd8.);
CLAIM_DATE_diff = CLAIM_DATE_A_n2 - CLAIM_DATE_B_n2;
IF (CLAIM_DATE_diff => 30 AND Med_def1516171920_count => 2 AND DxSCA1520_max_A = 1 AND DxSCA1520_max_B = 1)
THEN def&defnumb._Med_flag = 1; ELSE def&defnumb._Med_flag = 0;
RUN;
PROC SQL;
Create table temp.SCA_ICD10_def&defnumb._uniqID
as Select encrypted_id,
max(def&defnumb._Med_flag) as def&defnumb._Med_case
From temp.SCA_ICD10_def&defnumb._dates
Group by encrypted_id;
QUIT;
... View more