Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looking at similarity across rows

Status
Not open for further replies.

tweaked2005

Technical User
Jun 21, 2005
20
US
I have a dataset with 5 variables (syndrome, patientClass, datatype, location, date). It is possible that multiple records can match on everything but date. So as an example:
Dataset
=======
Obs Syndrome PatientClass DataType Location Date
1 S1 Inpatient Pediatrics Hosp1 1/1/07
2 S1 Inpatient Pediatrics Hosp1 1/5/07
3 S1 Inpatient Pediatrics Hosp1 1/30/07
4 S2 Outpatient Surgery Hosp2 1/30/07

I need to do the following:
Indicate in a comment field if records appear at the same Location, same Syndrome, PatientClass and DataType within a 1 week period. So in the above example, obs1 and obs2 should have a comment = "MultipleDays within 1 week".

I've tried doing something with first.var, but with multiple variables to evaluate I'm running into a wall. Does anyone have a good suggestion for accomplishing this task?

Thank you in advance for any assistance.
 
you could use sql, e.g. something like:
Code:
proc sql;
create table blar as
select 
   t1.*
  ,case when (select 
                count(*) 
              from 
                table t2
              where
                t2.syndrome = t1.syndrome
                and t2.patientclass = t1.patientclass
                and t2.datatype = t1.datatype
                and t2.location = t1.location
                and abs(t2.date - t1.date) <= 7) > 0 
        then 'MultipleDays within 1 week'
        else ' '
        end  
from
  table t1;
quit;
you would want to ensure you have an index on your fields though. (also, other sql solutions exist)

you could also try sorting the records then use a data step, for each by group load the date variable into an array, iterate over the array and compare dates then output the results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top