BookmarkSubscribeRSS Feed
Melk
Lapis Lazuli | Level 10

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

 

2 REPLIES 2
mkeintz
PROC Star

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.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Melk
Lapis Lazuli | Level 10
Actually each eye may or may not have the condition (disease was probably the wrong word, sorry). I am thinking it should be a GEE model for binary outcome to account for eye correlation.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1091 views
  • 0 likes
  • 2 in conversation