BookmarkSubscribeRSS Feed
newguy1580
Calcite | Level 5

Hi everyone,

so i'm working with a dataset that has the variable called hisugbev (high sugared beverage intake in servings/week). I'm trying to create a categorical variable with four levels and then create indicator variables from this categorical variable. For some reason after I create the categorical variable and the indicator variables, when I run my model for one of the parameter estimates i get a value of 0 and 0 d.f. Could anyone tell me what the reason might be for that?

This is my code below that may help:

if hisugbev=0 then sweet=1;

else if 0 gt hisugbev lt 1 then sweet=2;

else if 1 ge hisugbev le 3 then sweet=3;

else if 3 gt hisugbev then sweet=4;

if sweet=1 then sugar1=1; else sugar1=0;

if sweet=2 then sugar2=1; else sugar2=0;

if sweet=3 then sugar3=1; else sugar3=0;

if sweet=4 then sugar4=1; else sugar4=0;

proc phreg;

class sweet (param=ref ref='1');

model tpyrs*c5_1(0) = age sugar2 sugar3 sugar4;

run;

I get parameter estimates for sugar3 and sugar4 but not sugar2.

7 REPLIES 7
Reeza
Super User

Check your recoding.

ie

proc freq data=have;

table hisugbev*sweet;

run;

It's a good habit to always check your coding.

Your last condition is incorrect, it read

3 GT highsugbev

3>highsugbev.

It should be hisugbev>3

newguy1580
Calcite | Level 5

Ok so I did run proc freq and sweet=2 isn't even on the right hand side of the table...only 1,3,4

Reeza
Super User

Yup, that's what I've got as well.

If your variables are whole numbers, not decimals then 0 to 1 will never be coded because the boundaries aren't included.

newguy1580
Calcite | Level 5

Haha yes you're right! I got parameter estimates for sweet=2,3,and 4. That is so strange though...SAS doesn't know that .5 is between 0 and 1? Thank you so much for pointing this out to me!

Reeza
Super User

Actually, its my mistake, because at first glance they appear correct but I believe your boundaries are wrong, SAS does know how to categorize things properly. You should only have gt in the last condition.

data have;

do hisugbev=0 to 18 by 0.5;

output;

end;

run;

data want;

set have;

if hisugbev=0 then sweet=1;

else if 0<hisugbev<1 then sweet=2;

else if 1<=hisugbev <=3 then sweet=3;

else if hisugbev>3 then sweet=4;

run;

proc freq data=want;

table hisugbev*sweet/missing;

run;


newguy1580
Calcite | Level 5

Yup that's what I ended up doing when I changed my endpoints the only one I have gt for is in the last condition.

newguy1580
Calcite | Level 5

I don't get it...the coding for sweet=2 should work and it isn't like there are no observations in my dataset that don't fall under that condition, there definitely are. I checked all of that out earlier.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 1625 views
  • 1 like
  • 2 in conversation