Programming the statistical procedures from SAS

Chi-Sq

Reply
Occasional Contributor
Posts: 17

Chi-Sq

Hi,

 

I want to calculate odds ratios, confidence intervals, and overall p-value given this data set and not sure how to do it in SAS. 

      

DATA RACE_TEST;
INPUT RACE $ CMV_STATUS $ COUNT;
DATALINES;
Black CMV 10
Black NO CMV 16
White CMV 41
White NO_CMV 33
Asian CMV 20
Asian NO_CMV 5
Other CMV 16
Other NO_CMV 23

;

 

I would like the output to have an odds ratio (95% CI) for each race category, using white as the reference & 1 overall P-value to see if the race has no effect on CMV status. Is there a way to do all this in 1 statement?

 

Thank you!

 

PROC Star
Posts: 7,416

Re: Chi-Sq

Yes, if you can be lenient on how you define one line.

 

DATA RACE_TEST;
  INPUT RACE $ CMV_STATUS $ COUNT;
  DATALINES;
Black CMV 10
Black NO_CMV 16
White CMV 41
White NO_CMV 33
Asian CMV 20
Asian NO_CMV 5
Other CMV 16
Other NO_CMV 23
;
%macro doit (race);
  %let i=1;
  %do %while (%scan(&race,&i.) ne);
  
    proc freq data=RACE_TEST (where=(race in ("%scan(&race,&i.)",'White'))) order=data;
      weight count;
      tables RACE*CMV_STATUS/ chisq cmh;
    run;
    %let i=%eval(&i+1);
  %end;
%mend doit;

%doit(Black Asian Other)

Art, CEO, AnalystFinder.com

 

PROC Star
PROC Star
Posts: 185

Re: Chi-Sq

Another approach, using GENMOD, that produces the same results as the solution offered by @art297 (thanks to Art for correcting the dataset):

 

DATA RACE_TEST;
  INPUT RACE $ CMV_STATUS $ COUNT;
  DATALINES;
Black CMV 10
Black NO_CMV 16
White CMV 41
White NO_CMV 33
Asian CMV 20
Asian NO_CMV 5
Other CMV 16
Other NO_CMV 23
;

proc freq data=race_test;
    table race*cmv_status / chisq;
    weight count;
    run;

proc genmod data=race_test;
    class race cmv_status;
    model cmv_status = race / dist=bin type3;
    freq count;
    lsmeans race / ilink cl oddsratio;
    run;

 

The FREQ procedure is not critical to the process, but it does provide some nice estimates, easy test of interaction of race and cmv_status (i.e., whether race and cmv_status are independent; here, they are not), and an overall test of race, all of which you can either find or extract from GENMOD. FREQ of course is limited to categorical variables, whereas GENMOD can also do continuous predictors.

 

Still not one line Smiley Happy 

 

Ask a Question
Discussion stats
  • 2 replies
  • 149 views
  • 3 likes
  • 3 in conversation