View Full Version : Subsetting unique data


DRiya
01-12-2009, 01:33 PM
I am working with medical data and am trying to figure out how to get at information on unique patients. Currently, my original dataset has every hospital visit, so anyone who made more than one visit in a year shows up multiple times. I created a subset using FIRST. to get basic numbers on patients, but this means I lose information on subsequent trips to the hospital.

I need to find a way to a) create a counter for each visit a patient makes to the hospital so I can get total numbers of visits for the year, b) sort through the visits for each patient to find specific information (ex. some patients only listed insurance information for one visit, so I lose it if it is not listed for the first trip). Thanks!

vinux
01-12-2009, 08:51 PM
I didn't get the b) part. I guess the you have patient id and purpose of the visit ( say pid & purpose). And it may happen that the purpose of the visit may change in each visit. right?

a) either you can use proc sql ( use group by pid) or proc summary ( class pid) or use LAST (use counter: retain).
b) if you can prepare different dataset using where purpose= "insurance"

TheAnalysisFactor
01-12-2009, 10:33 PM
I am not a fabulous SAS programmer, and am not familar with the procs Richie suggested.

But to do part a), I would use the First. (yes the dot is part of the function) function and the Retain statement. It's a little tricky, but it has saved my programming butt more than once.

I believe you have to do it in a data step and the key is to do proc sort first, and also use the same By statement in the proc sort and within the data step.

Here's an example, which I'm sure is not correct (it's been a while), but should help you get started. This stuff is in the manuals.

proc sort;
by patient date;

data new; set old;
by patient date;
if first.date = 1 then visit=1;
else visit=visit+1;
retain visit;

Karen