I have two variables - spline variable of height and another continuous variable. How do I write contrast to get difference in spline effects of height with respect to a reference at height=60 for interacting effect of weight? I have written the code but the ESTIMATE results do not coincide with the manual calculation. Any tip would be greatly appreciated. Thanks.
**sample data;
data mydata;
call streaminit(12345);
/* Generate 2,000 matched case-control strata (1 case, 3 controls per stratum) */
do stratum_id = 1 to 2000;
/* Assign a random Zip code AC percentage to the stratum (0% to 100%) */
ac_percent = rand("Uniform", 0.10, 0.90);
do obs = 1 to 4;
/* Temperature range: 5°C to 35°C */
temp = rand("Uniform", 5, 35);
/* First observation in stratum is the case (Y=1), others are controls (Y=0) */
if obs = 1 then Y = 1;
else Y = 0;
output;
end;
end;
run;
proc phreg data=mydata;
strata stratum_id;
/* Define B-spline for temperature */
effect temp_bs = spline(temp / degree=3 knotmethod=equal(4));
/* Y=0 as censoring variable simulates case-control outcome */
model obs*Y(0) = temp_bs temp_bs*ac_percent / ties=discrete;
ESTIMATE 'Log-OR (Temp=5 vs 20) at AC=0.10' temp_bs [1, 5] [-1, 20] temp_bs*ac_percent [1, 0.10 5] [-1, 0.10 20];
store work.spline_model;
run;
***this does not coincide with the following code;
data grid_data;
do temp = 5 to 35 by 0.5;
do ac_percent = 0.10 to 0.90 by 0.05;
output;
end;
end;
run;
/* Set Reference Temperature T0 = 20°C */
data ref_data;
temp = 20;
/* AC percentage value here cancels out when taking differences */
ac_percent = 0;
run;
/* Score grid points */
proc plm restore=work.spline_model;
score data=grid_data out=grid_scored pred=link_grid stderr=se_grid; *pred=xbeta;
run;
/* Score reference point (T0 = 20°C) */
proc plm restore=work.spline_model;
score data=ref_data out=ref_scored pred=link_ref stderr=se_ref;; *pred=xbeta;
run;
/* Merge reference value to grid and compute Odds Ratio relative to 20°C */
data plot_data;
if _N_ = 1 then set ref_scored(keep=link_ref);
set grid_scored;
* Log Odds Ratio = Log-hazard(T) - Log-hazard(T0=20°C);
log_or = link_grid - link_ref;
or_val = exp(log_or);
run;
Because the AC value is involved in the interaction, I do not think it would cancel out as your comment in the REF_DATA suggests (e.g. it should not be zero). If you set the AC_PERCENT=.10 instead of 0 then it will match what the ESTIMATE statement is giving.
Because the AC value is involved in the interaction, I do not think it would cancel out as your comment in the REF_DATA suggests (e.g. it should not be zero). If you set the AC_PERCENT=.10 instead of 0 then it will match what the ESTIMATE statement is giving.
Thanks Ksharp. The documents do not give exactly what I was looking for. But I figured out what is going on. My manual calculation is at a specific level of AC and the numbers do match.
You might also find it useful to plot the hazard ratio as a function of your two predictors as shown in the "Hazard Ratios for a Splined Variable Interacting with a Continuous Variable" section of this knowledge base article. With the plot, you can visualize the change over either predictor.
It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.
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.