I am trying to run PROC PHREG for a Cox Proportional Hazards model. The output is reading 0 censored observations, though the PROC FREQ I ran shows several observations in the 0 (censored) category. Also, it is not recognizing some of the other variables in my model statement, including age_b and age_ph and bmichg_b and bmichg_ph..and also event_b and event_ph. The variable in the error message seems to switch every time. Any ideas why this is happening? Sample code below. Thank you!
/* change BMI PCT CHANGE into numeric.*/ data data2; set data1; if bmipct_chg_b = "RC" then bmipct_chg_b = .; else if bmipct_chg_ph = "RC" then bmipct_chg_ph = .; run; data data2; set data2; bmichg_b = input(bmipct_chg_b, BEST.); format bmichg_b BEST.; bmichg_ph = input(bmipct_chg_ph, BEST.); format bmichg_ph BEST.; run; proc means data=data2; var bmichg_b; var bmichg_ph; run; /* change age_chg_b and age_chg_ph into numeric*/ data data2; set data1; if age_chg_b = "RC" then age_chg_b = .; else if age_chg_ph = "RC" then age_chg_ph = .; run; data data2; set data2; age_b = input(age_chg_b, BEST.); format age_b BEST.; age_ph = input(age_chg_ph, BEST.); format age_ph BEST.; run; proc means data=data2; var age_b; var age_ph; run; /* change event b and event ph into numeric */ data data2; set data1; event_b = input(event_c, BEST.); format event_b BEST.; event_ph = input(event_c_ph, BEST.); format event_ph BEST.; run; proc freq data=data2; table event_b; table event_ph; run; /* Confirm: higher BMI and earlier Age At Puberty - Cox Models*/ /* Breast*/ title "BMI Percentile Change and Breast Development"; proc phreg data=data2; model age_b*event_b(0) = bmichg_b agemos_baseline/risklimits covb ties=efron; run; /* PH*/ title "BMI Percentile Change and Pubic Hair Development"; proc phreg data=data2; model age_ph*event_ph(0)=bmichg_ph agemos_baseline/risklimits covb ties=efron; run;
Check the distribution of variables when censor = 0.
SAS excludes any observations where any variable is missing, so if other variables are missing for your censored observations it will exclude those observations.
You're also overwriting data2 in one of your latter steps.
Using this type of programming style is bad, mostly because it makes it really really hard to find mistakes. Instead, just increment it each time up one.
instead of:
data data2; set data2;
use:
data data3; set data2;
This is a problem, note you reference data1 so all the other conversions are erased now.
/* change event b and event ph into numeric */
data data2; set data1;
event_b = input(event_c, BEST.);
format event_b BEST.;
event_ph = input(event_c_ph, BEST.);
format event_ph BEST.;
run;
This is also incorrect - I would expect a message in the log or error for these lines.
if bmipct_chg_b = "RC" then bmipct_chg_b = .;
Since the variable is character you should use empty quotation marks, or I like to use CALL MISSING, since it doesn't matter if the variable is numeric or character.
if bmipct_chg_b = "RC" then call missing(bmipct_chg_b);
Fix the data reference issues, fix the conversion issues and try again. The data reference is a big one in your steps, but this is a logical error, not a syntax error so it's harder to find.
@amd23050 wrote:
I am trying to run PROC PHREG for a Cox Proportional Hazards model. The output is reading 0 censored observations, though the PROC FREQ I ran shows several observations in the 0 (censored) category. Also, it is not recognizing some of the other variables in my model statement, including age_b and age_ph and bmichg_b and bmichg_ph..and also event_b and event_ph. The variable in the error message seems to switch every time. Any ideas why this is happening? Sample code below. Thank you!
/* change BMI PCT CHANGE into numeric.*/ data data2; set data1; if bmipct_chg_b = "RC" then bmipct_chg_b = .; else if bmipct_chg_ph = "RC" then bmipct_chg_ph = .; run; data data2; set data2; bmichg_b = input(bmipct_chg_b, BEST.); format bmichg_b BEST.; bmichg_ph = input(bmipct_chg_ph, BEST.); format bmichg_ph BEST.; run; proc means data=data2; var bmichg_b; var bmichg_ph; run; /* change age_chg_b and age_chg_ph into numeric*/ data data2; set data1; if age_chg_b = "RC" then age_chg_b = .; else if age_chg_ph = "RC" then age_chg_ph = .; run; data data2; set data2; age_b = input(age_chg_b, BEST.); format age_b BEST.; age_ph = input(age_chg_ph, BEST.); format age_ph BEST.; run; proc means data=data2; var age_b; var age_ph; run; /* change event b and event ph into numeric */ data data2; set data1; event_b = input(event_c, BEST.); format event_b BEST.; event_ph = input(event_c_ph, BEST.); format event_ph BEST.; run; proc freq data=data2; table event_b; table event_ph; run; /* Confirm: higher BMI and earlier Age At Puberty - Cox Models*/ /* Breast*/ title "BMI Percentile Change and Breast Development"; proc phreg data=data2; model age_b*event_b(0) = bmichg_b agemos_baseline/risklimits covb ties=efron; run; /* PH*/ title "BMI Percentile Change and Pubic Hair Development"; proc phreg data=data2; model age_ph*event_ph(0)=bmichg_ph agemos_baseline/risklimits covb ties=efron; run;
Check the distribution of variables when censor = 0.
SAS excludes any observations where any variable is missing, so if other variables are missing for your censored observations it will exclude those observations.
You're also overwriting data2 in one of your latter steps.
Using this type of programming style is bad, mostly because it makes it really really hard to find mistakes. Instead, just increment it each time up one.
instead of:
data data2; set data2;
use:
data data3; set data2;
This is a problem, note you reference data1 so all the other conversions are erased now.
/* change event b and event ph into numeric */
data data2; set data1;
event_b = input(event_c, BEST.);
format event_b BEST.;
event_ph = input(event_c_ph, BEST.);
format event_ph BEST.;
run;
This is also incorrect - I would expect a message in the log or error for these lines.
if bmipct_chg_b = "RC" then bmipct_chg_b = .;
Since the variable is character you should use empty quotation marks, or I like to use CALL MISSING, since it doesn't matter if the variable is numeric or character.
if bmipct_chg_b = "RC" then call missing(bmipct_chg_b);
Fix the data reference issues, fix the conversion issues and try again. The data reference is a big one in your steps, but this is a logical error, not a syntax error so it's harder to find.
@amd23050 wrote:
I am trying to run PROC PHREG for a Cox Proportional Hazards model. The output is reading 0 censored observations, though the PROC FREQ I ran shows several observations in the 0 (censored) category. Also, it is not recognizing some of the other variables in my model statement, including age_b and age_ph and bmichg_b and bmichg_ph..and also event_b and event_ph. The variable in the error message seems to switch every time. Any ideas why this is happening? Sample code below. Thank you!
/* change BMI PCT CHANGE into numeric.*/ data data2; set data1; if bmipct_chg_b = "RC" then bmipct_chg_b = .; else if bmipct_chg_ph = "RC" then bmipct_chg_ph = .; run; data data2; set data2; bmichg_b = input(bmipct_chg_b, BEST.); format bmichg_b BEST.; bmichg_ph = input(bmipct_chg_ph, BEST.); format bmichg_ph BEST.; run; proc means data=data2; var bmichg_b; var bmichg_ph; run; /* change age_chg_b and age_chg_ph into numeric*/ data data2; set data1; if age_chg_b = "RC" then age_chg_b = .; else if age_chg_ph = "RC" then age_chg_ph = .; run; data data2; set data2; age_b = input(age_chg_b, BEST.); format age_b BEST.; age_ph = input(age_chg_ph, BEST.); format age_ph BEST.; run; proc means data=data2; var age_b; var age_ph; run; /* change event b and event ph into numeric */ data data2; set data1; event_b = input(event_c, BEST.); format event_b BEST.; event_ph = input(event_c_ph, BEST.); format event_ph BEST.; run; proc freq data=data2; table event_b; table event_ph; run; /* Confirm: higher BMI and earlier Age At Puberty - Cox Models*/ /* Breast*/ title "BMI Percentile Change and Breast Development"; proc phreg data=data2; model age_b*event_b(0) = bmichg_b agemos_baseline/risklimits covb ties=efron; run; /* PH*/ title "BMI Percentile Change and Pubic Hair Development"; proc phreg data=data2; model age_ph*event_ph(0)=bmichg_ph agemos_baseline/risklimits covb ties=efron; run;
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.