Help using Base SAS procedures

Changing reference level for categorical variable in PROC SURVEYREG

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 82
Accepted Solution

Changing reference level for categorical variable in PROC SURVEYREG

Hi, I'm trying to change the reference level for categorical variable in proc surveyreg.  Let's say I have the following code:

proc surveyreg data = temp;

weight weightvar;

strata stratum;

cluster psu;

class race;

model income = race /solution;

run;

Let's say that class is a four-level categorical variable with race = 1 being white, race = 2 being black, race = 3 being Asian, race = 4 being Hispanic.  It seems like proc surveyreg will use the highest value of race (race = 4, Hispanic) as the default baseline, but I'd like to set the default to be another level (say, race = 2 or black).  How do I do this without recoding my race variable?  [I could do a descending sort of race and include the option "order = data" on the proc surveyreg line, but that would only help me if I wanted to make race = 1 my baseline]. 


Accepted Solutions
Solution
‎08-29-2011 04:56 PM
Frequent Contributor
Posts: 104

Re: Changing reference level for categorical variable in PROC SURVEYREG

The PROC SURVEYREG documentation talks about using formatted value and using the ORDER= options on the SURVEYREG statement.

You can do this two ways:

- change the value in the dataset itself, or

- use proc format tricks. e.g., your data is rece = '1','2','3','4', '4' would be used by default as you noted.  Suppose you want to use '3' as reference class,

proc format;

     value $race

          '1' = 'A White'

          '2' = 'B Black'

          '3' = 'D Asian'

          '4' = 'C Hispanic'

     ;

run;

proc surveyreg order=formatted data=temp;

     class race;     format race $race.;

     ...

'3' would be used as reference because its formatted value is sorted the highest.

PROC SURVEYLOGISTIC, on the other hand, allows you explicit control over the reference class.  Here's a link to a paper showing examples http://www2.sas.com/proceedings/sugi31/140-31.pdf.  This is probably not supported by SURVEYREG though (I can't test at the moment).

PROC SURVEYLOGISTIC DATA=ALL(WHERE=(20<=RIDAGEYR)) ;

CLUSTER SDMVPSU; STRATA SDMVSTRA;

CLASS SEX(ref='M') AGE1(ref=FIRST) RACE(ref='Non-Hispanic White');

WEIGHT WTMEC4YR;

MODEL HIGHTC(EVENT='1') = SEX AGE1 RACE ;

RUN;

View solution in original post


All Replies
Solution
‎08-29-2011 04:56 PM
Frequent Contributor
Posts: 104

Re: Changing reference level for categorical variable in PROC SURVEYREG

The PROC SURVEYREG documentation talks about using formatted value and using the ORDER= options on the SURVEYREG statement.

You can do this two ways:

- change the value in the dataset itself, or

- use proc format tricks. e.g., your data is rece = '1','2','3','4', '4' would be used by default as you noted.  Suppose you want to use '3' as reference class,

proc format;

     value $race

          '1' = 'A White'

          '2' = 'B Black'

          '3' = 'D Asian'

          '4' = 'C Hispanic'

     ;

run;

proc surveyreg order=formatted data=temp;

     class race;     format race $race.;

     ...

'3' would be used as reference because its formatted value is sorted the highest.

PROC SURVEYLOGISTIC, on the other hand, allows you explicit control over the reference class.  Here's a link to a paper showing examples http://www2.sas.com/proceedings/sugi31/140-31.pdf.  This is probably not supported by SURVEYREG though (I can't test at the moment).

PROC SURVEYLOGISTIC DATA=ALL(WHERE=(20<=RIDAGEYR)) ;

CLUSTER SDMVPSU; STRATA SDMVSTRA;

CLASS SEX(ref='M') AGE1(ref=FIRST) RACE(ref='Non-Hispanic White');

WEIGHT WTMEC4YR;

MODEL HIGHTC(EVENT='1') = SEX AGE1 RACE ;

RUN;

Frequent Contributor
Posts: 82

Changing reference level for categorical variable in PROC SURVEYREG

Thanks so much for the tip on playing with the formats - that did the trick.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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