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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.