* There is a class of clinical problems that are trivial to solve with IML, but very difficult with any other SAS procedure. This is just one of them; Proc Iml; * Suppose for each patient you have data for 38 different lab tests taken weekly for 7 weeks for 60 patients. Data for 1 patient, 7 tests and 7 weeks are shown below, generalizing to 60 patients and 38 tests is easy. ( results are severity, 0 least severe -- 9 most severe) Nam={ 'BUN' 'HDL' 'CO2' 'WBC' 'LDL' 'LIP' 'NH4' }; Num={ 2 6 7 2 2 0 8, 1 9 4 0 1 4 6, 3 2 0 2 9 0 5, 7 3 5 7 6 1 3 4 1 0 3 4 4 2, 5 5 3 0 7 2 0, 6 4 5 1 6 2 3, }; * You need to produce this listing Three most abnormal tests, Median and Best 3 (note: there are 49 tests taken 7 weeks x 7 tests 49th tst is the worst of the 49, 1st is the best) Worst 3 Median Best 3 ----------------------------- ------ -------------------------- 49th 48th 47th 25th 1st 2nd 3rd Patient Tst Val Tst Val Tst Val Tst Val Tst Val Tst Val Tst Val ------- --- --- --- --- --- --- --- --- --- --- --- --- --- --- 1 WBC 9 HDL 9 LDL 9 BUN 3 ANC 0 HMO 0 CRE 0 2 HDL 9 AMS 9 CRE 8 CRE 4 ALT 0 ALP 0 ALD 1 . ... 60 LDL 9 ALT 9 HDL 8 CO2 4 WBC 0 ALB 0 OX2 1 You need to find for each patient 1. The median test value and its test name 2. The three worst test outcomes and the Test Name 3. The three most normal test outcomes and the test names. Solution ======== ; NamRep=Repeat(Nam,7,1); /* Shape like Num */ HoldNum=Num; /* Need a copy for sort to work - rank selection */ HoldNam=NamRep; /* Need a copy for sort to work - rank selection sort */ Ranks=Rank(Num[,]); /* Buids a matrix like nums but with ranks instead of values */ /* you might want to Print Ranks */ Num[Ranks]=HoldNum; /* Num Ranks is now sorted Num[1,1] has lowest test value ie 0 */ /* Num[7,7] has highest lab test value ie 9 */ NamRep[Ranks]=HoldNam; /* NamRep[1,1] has the test name associated with Num[1,1] */ MedianNum=Num[4,4]; /* middle value of sorted list of 49 tests */ MedianNam=NamRep[4,4]; /* name associated with middle value */ Print MedianNam MedianNum; run; quit; /* Note: Proc SQL does not have median or ordinal function ( 47 Lab tests is problematic ) Note: Transpose then proc means will give order statistics but will not carry test name Note: In datastep Worst=Ordinal(47,of Alb--Wbc) will give worst order statistics but not the lab name. You can get the lab name but it requires an additiona1 array and a transformation on lab values. However you cannot easily get a worst three that span records. */