BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
yilijiaer
Calcite | Level 5

I want to use bcd4=1 as the reference level, but there is Error 22-322 and I would like someone to help with it, thank you!

 

data workdata;set workdata;
if LBDBCDSI<=1.78 then bcd4=1;
if 1.78<LBDBCDSI<=3.56 then bcd4=2;
if 3.56<LBDBCDSI<=6.23 then bcd4=3;
if 6.23<LBDBCDSI then bcd4=4;
run; 

proc univariate data=workdata2; var urine_cd; weight WTSHM6YR;run; /* take down the min, 25%, 50%, 75%, and the max value. */
data workdata2;set workdata2;
if urine_cd<=1.38 then ucd4=1;
if 1.38<urine_cd<=2.69 then ucd4=2;
if 2.69<urine_cd<=5.09 then ucd4=3;
if 5.09<urine_cd then ucd4=4;
run; 

/* fit data by using restricted cubic splines */
ods select ANOVA ParameterEstimates SplineKnots;
proc glmselect data=workdata;
  effect spl = spline(RIDAGEYR / details naturalcubic basis=tpf(noint)                 
                               knotmethod=percentiles(5) );
   model LBDBCDSI = spl / selection=none;         /* fit model by using spline effects */
   output out=SplineOut predicted=Fit;            /* output predicted values for graphing */
quit;
 
title "Restricted Cubic Spline Regression";
proc sgplot data=SplineOut noautolegend;
   scatter x=RIDAGEYR y=LBDBCDSI;
   series x=RIDAGEYR y=Fit / lineattrs=(thickness=3 color=red);
run;

/*model_1*/
data workdata;set workdata;/*years modeled as restricted cubic spline with 5 knots*/
if RIDAGEYR<=30 then age=1;
if 30<RIDAGEYR<=40 then age=2;
if 40<RIDAGEYR<=49 then age=3;
if 49<RIDAGEYR<=61 then age=4;
if 61<RIDAGEYR<=71 then age=5;
if 71<RIDAGEYR then age=6;
run;

data workdata;set workdata;/*education*/
if DMDEDUC=1 then edu=1;
if DMDEDUC=2 then edu=2;
if DMDEDUC=3 then edu=3;
run;

data workdata;set workdata;/*race*/
if RIDRETH1=3 then race=0;
else if RIDRETH1=4 then race=1;
else if RIDRETH1=1 then race=2;
else race=3;
run;

/*linear regression-model1-blood cd*/
proc surveyreg data=workdata;
class bcd4 (ref='1') age RIAGENDR race edu;
model BPXSAR=bcd4 age RIAGENDR race edu/ vadjust=none;
stratum sdmvstra;
cluster sdmvpsu;
weight wtmec6yr;
run; 

 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

@yilijiaer wrote:

 Could you give me an example of using "order=" in CLASS statement to set reference levels?


Just correct the example in your own post:

  1. Create a numeric format for the numeric variable bcd:
    proc format;
    value bcd
    1 = 'D Q1'
    ...
  2. Modify the PROC SURVEYREG step similarly to what you did already below your PROC FORMAT step:
    proc surveyreg data=workdata order=formatted;
    class bcd age ...;
    format bcd bcd.;
    model ...

View solution in original post

7 REPLIES 7
yilijiaer
Calcite | Level 5
data workdata;set workdata;
if LBDBCDSI<=1.78 then bcd=1;
if 1.78<LBDBCDSI<=3.56 then bcd=2;
if 3.56<LBDBCDSI<=6.23 then bcd=3;
if 6.23<LBDBCDSI then bcd=4;
run; 

proc format;
     value $bcd
          '1' = 'D Q1'
          '2' = 'A Q2'
          '3' = 'B Q3'
          '4' = 'C Q4';
run;
proc surveyreg order=formatted data=workdata;
     class bcd;     format bcd $bcd.;

proc surveyreg data=workdata; 
class bcd(ref='1') age RIAGENDR race edu;
model BPXSAR=bcd4 age RIAGENDR race edu/ vadjust=none; 
stratum sdmvstra;  
cluster sdmvpsu;  
weight wtmec6yr; 
run;

Thank you! I tried this one, but it still does not work.

unison
Lapis Lazuli | Level 10

If you aren’t running your code start to finish each time, you’re likely overwriting for data set workdata multiple times. I suggest changing the output name for each step.

 

if you need bcd to be character eventually why not define it that way to begin with?

data workdata2;set workdata;
if LBDBCDSI<=1.78 then bcd='1';
if 1.78<LBDBCDSI<=3.56 then bcd='2';
if 3.56<LBDBCDSI<=6.23 then bcd='3';
if 6.23<LBDBCDSI then bcd='4';
run; 

-unison 

-unison
FreelanceReinh
Jade | Level 19

Hi @yilijiaer,

 

The reason for the error 22-322 is that you're using a relatively old release of SAS/STAT, probably SAS/STAT 13.2 or earlier. You can verify this by submitting this step:

proc product_status;
run;

The REF= option after a CLASS variable is mentioned in the PROC SURVEYREG documentation of SAS/STAT 14.1 and later releases. So, you should use the ORDER= technique that has been suggested and omit the "(ref='1')" option in the CLASS statement. It doesn't matter if variable bcd is numeric or character, but the type of the format must match the type of the variable (i.e., either make bcd a character variable as unison has suggested or create a numeric format without a $ sign before its name and without single quotes on the left of the equals signs).

yilijiaer
Calcite | Level 5

Yes, you are right, I am using SAS/STAT 13.2. I think it is the reason. Could you give me an example of using "order=" in CLASS statement to set reference levels? Thank you so much!

FreelanceReinh
Jade | Level 19

@yilijiaer wrote:

 Could you give me an example of using "order=" in CLASS statement to set reference levels?


Just correct the example in your own post:

  1. Create a numeric format for the numeric variable bcd:
    proc format;
    value bcd
    1 = 'D Q1'
    ...
  2. Modify the PROC SURVEYREG step similarly to what you did already below your PROC FORMAT step:
    proc surveyreg data=workdata order=formatted;
    class bcd age ...;
    format bcd bcd.;
    model ...
Kurt_Bremser
Super User

Please do not mix code and log text. Either show the log from the beginning, or the code. It could well be that your problem is caused by something from line 674 up.

And supply some example data in usable form (data step with datalines) so we have something to play around with.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 871 views
  • 3 likes
  • 5 in conversation