Hi All,
I'm hoping you can help with my code below. I ran this on Friday and everything was working so I'm not sure why all of a sudden I'm getting this error message.
I formatted my variables in earlier code. The variable I'm having problems with is diabetes_P1 which I formatted to diabetes_baseline where 0=no and 1 = yes.
Proc format; value BMI_group 0 - <18.5 = Underweight 18.5 - 24.9 = Healthy 25.0 - <30.0 = Overweight 30.0 - 100.0 = Obese other = missing; value diabetes_baseline 0 = No 1 = Yes other = Missing; value diabetes_final 0 = No 1 = Yes other = Missing;
I then wrote code to make new variables to calculate the change in Fev1 and Fev1/FVC over time. The problem is in the diabetes_p1 variable in my prc glm
data working4; ***this works; set working3; change_fev1 = fev1pp_Post_p3 - fev1pp_Post_p1; change_fev1_FVC = fev1_FVC_post_p3 - Fev1_FVC_post_p1; run; proc glm data=working4; class diabetes_P1(ref= '0') finalgold_P1 (ref='0'); model change_fev1_FVC = diabetes_P1 finalgold_p1 diabetes_P1*finalgold_p1; lsmeans diabetes_P1 finalgold_p1 diabetes_P1*finalgold_p1 / pdiff; format finalgold_p1 final_gold_stage. diabetes_P1 diabetes_baseline.; run; ERROR: Invalid reference value for Diabetes_P1.
I tried changing the ref="No" since that is what I formatted it to, but that resulted in the same the error.
I ran proc contents data=working4;
run;
Alphabetic List of Variables and Attributes # Variable Type Len Format Informat Label 17 ATS_PackYears_P1 Num 8 Pack years, from Resp Questionnaire 32 ATS_PackYears_P3 Num 8 Pack years, from Resp Questionnaire 5 Age_P1 Num 8 Age at current visit 19 Age_P3 Num 8 Age at current visit 7 BMI_P1 Num 8 BMI 21 BMI_P3 Num 8 BEST16. 34 Change_P1_P3_Smoking_Status Char 4 Change P1-P3: Smoking Status 12 CortsterOral_P1 Num 8 11. 11. Oral corticosteroids 26 CortsterOral_P3 Num 8 BEST16. 11 Cortsterinhal_P1 Num 8 11. 11. Inhaled corticosteroids 25 Cortsterinhal_P3 Num 8 BEST12. BEST16. 28 DLco_GLI_pp_PbHb_adj_P3 Num 8 DLco % predicted GLI, adjusted for Hb and altitude 8 Diabetes_P1 Num 8 11. 11. Diabetes
I tried changing the diabetes_P1 variable to diabetes given that is the label attached to it but then get this:
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 72 73 proc glm data=working4; 74 class diabetes(ref= 'No') finalgold_P1 (ref='0'); ERROR: Variable DIABETES not found. NOTE: The previous statement has been deleted. 75 model change_fev1_FVC = diabetes_P1 finalgold_p1 diabetes_P1*finalgold_p1; 76 lsmeans diabetes_P1 finalgold_p1 diabetes_P1*finalgold_p1 / pdiff; ERROR: Only CLASS variables allowed in this effect. NOTE: The previous statement has been deleted. 77 format finalgold_p1 final_gold_stage. diabetes_P1 diabetes_baseline.; 78 run;
Any suggestions?
Then please provide more details of that failed attempt, e.g., the complete log of the PROC GLM step.
What you've shown so far is
If diabetes_P1(ref='No') is rejected with the same error message "Invalid reference value ...", then your PROC FORMAT step might contain invisible characters. Note that format labels should normally be quoted:
proc format; value BMI_group 0 - <18.5 = "Underweight" 18.5 - 24.9 = "Healthy" ...
although omitting the quotes works in most cases. Without the quotes you cannot see the difference, e.g., between "No" and "No ", where the trailing blank in the latter is in fact a non-breaking space character. In this case ref='No' would not work because of that invisible third character in the formatted value.
Hi @kristiepauly,
Reference values must always be specified as formatted values, so class diabetes_P1(ref='No') ... should work.
Hi @FreelanceReinh. I tried that. It did not work.
Then please provide more details of that failed attempt, e.g., the complete log of the PROC GLM step.
What you've shown so far is
If diabetes_P1(ref='No') is rejected with the same error message "Invalid reference value ...", then your PROC FORMAT step might contain invisible characters. Note that format labels should normally be quoted:
proc format; value BMI_group 0 - <18.5 = "Underweight" 18.5 - 24.9 = "Healthy" ...
although omitting the quotes works in most cases. Without the quotes you cannot see the difference, e.g., between "No" and "No ", where the trailing blank in the latter is in fact a non-breaking space character. In this case ref='No' would not work because of that invisible third character in the formatted value.
@FreelanceReinh @Quentin . I deleted the code and rewrote and it works fine now. Gotta love SAS /s. Thank you!
Interesting, ref='No' Should work. Maybe double-check the capitalization in your format and ref= to make sure they match? This trivial example works for me:
proc format ;
value age
low-13='No'
14-high='Yes'
;
run ;
proc glm data=sashelp.class ;
class age(ref='No') ;
model height=age ;
format age age. ;
run ;
quit ;
Can you post the full log from your PROC FORMAT step and PROC GLM step with ref='No'?
When things stop working or for a final test make it a habit to create a new SAS session and re-run everything. This helps you avoid that something you've changed in a previous run in the same SAS session impacts your result.
Just on a side note: Your format BMI_group will return MISSING for values like 24.95 I assume that's not what you want.
proc format;
value BMI_group
0 - <18.5 = Underweight
18.5 - 24.9 = Healthy
25.0 - <30.0 = Overweight
30.0 - 100.0 = Obese
other = missing;
value BMI_group_new
0 -< 18.5 = 'Underweight'
18.5 -< 25 = 'Healthy'
25 -< 30 = 'Overweight'
30 - 100 = 'Obese'
other = 'missing'
;
run;
data test;
input val;
BMI_group =put(val,bmi_group.);
BMI_group_new =put(val,bmi_group_new.);
datalines;
18.49
18.5
24.89
24.9
24.99
25
29.99
30
30.01
;
run;
proc print data=test;
run;
@Patrick Thank you for picking up on that. 🙂
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.