I have some eye-level data and I just want to run a simple chi-square comparing the proportion of disease X between race. Since the data is clustered, is there an option I can use in proc freq to adjust for the correlation of eyes between patients?
ID EYE X RACE
1 R 0 A
1 L 0 A
2 R 1 W
2 L 0 W
I presume that "having the disease" is signified by both eyes having X=1, or either eye have X=1, correct? If so, create one record per person, with a new variable NEWX, which takes the maximum value of X for each ID. Then you can proc freq, crosstabulating newx with race.
data have;
input ID EYE :$1. X RACE :$1.;
datalines;
1 R 0 A
1 L 0 A
2 R 1 W
2 L 0 W
run;
data want (drop=eye);
set have (where=(x=0))
have (where=(x=1));
by id;
if last.id;
rename x=new_;
run;
The data step above interleaves all the X=0 records with the X=1 records, within each by group. So no matter the original order of x values within an id, the incoming data will present the X=1 record last, if there is an x=1 record. Otherwise the last record for the id will be an x=0:
This program depends on the data being sorted by ID, but it doesn't care about the order of X within id, nor the order or R vs L within the id.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.