Risk differences or ratios with the RISK statement in PROC LOGSELECT


You can estimate risk differences and risk ratios (relative risks) using the RISK statement in PROC LOGSELECT beginning in SAS® Viya® 2026.05. While the RISK statement is not available in PROC LOGISTIC in SAS Viya or SAS® 9.4, you can estimate these statistics and other functions of risks using the NLMeans macro in combination with PROC LOGISTIC or other procedure that fits a binary or multinomial response model. Various ways of estimating the risk difference and ratio, including use of the NLMeans macro in SAS 9.4 and the RISK statement in PROC LOGSELECT, are shown in SAS KB0057272 and SAS KB0056989. Links to additional examples of using the NLMeans macro are given in the NLMeans documentation.

However, the RISK statement in PROC LOGSELECT does not, in general, define risks for a categorical (CLASS) predictor in the same way as the LSMEANS statement, which is commonly used to estimate risks and is used in combination with the NLMeans macro to estimate risk differences, ratios, or other functions of risks. As a result, you might see differences in the estimates provided by the RISK statement and the NLMeans macro. For a categorical predictor in a model that contains no additional categorical predictors, risk difference estimates from the RISK statement and NLMeans agree.Note An example is available in SAS KB0057272.

For a given model with multiple predictors, the risks can be defined in many ways, so you should consider which definition makes sense for your situation. Both the RISK and LSMEANS statements offer the AT option for setting the coefficients on the model parameters defining the risks, and the LSMEANS statement also provides the OM= and BYLEVEL options that affect the coefficients. However, it is not possible to define the risks from the RISK statement in the same way as the LSMEANS statement when additional CLASS predictors are in the model.

Note that another way to define the risk is as the average of the predicted risks (event probabilities) across the observations rather than as fixed coefficients on the model parameters as done by the LSMEANS or RISK statement. These averages are called predictive margins and can be obtained using the MARGINS statement in PROC LOGISTIC in SAS Viya or the Margins macro in SAS 9.4 or SAS Viya.

The following example illustrates a model with multiple CLASS variables and discusses the reason for the difference in the risk difference estimates produced by the RISK statement and the NLMeans macro using LS-means.

Example: Risk differences for a CLASS predictor

This example uses the neuralgia data presented in the example titled "Logistic Modeling with Categorical Predictors" in the LOGISTIC procedure documentation. After starting a CAS session and creating a CAS libref called SASCAS1, the following statements copy the neuralgia data set into a CAS table. PROC LOGSELECT then fits a logistic model involving two CLASS predictors and two continuous predictors. The RISK statement requests pairwise risk difference estimates among the three Treatments (DIFF=ALL) as well as estimates of the individual Treatment risks used in each difference (SHOWPROBS). The E option shows the linear combination of model parameters that the RISK statement uses to define the individual risks. Risk ratios (relative risks) rather than differences can be obtained by specifying the TYPE=RELATIVE option:

data sascas1.neur;
   set neuralgia;
   run;
proc logselect data=sascas1.neur;
   class Treatment Sex;
   model Pain = Treatment Sex Age Duration;
   risk treatment / e diff=all showprobs;
   run;

Selected output from PROC LOGSELECT below includes the parameter estimates, the coefficients on the parameters that define each risk, and the estimated risk differences. In the risk coefficients table, pairs of columns define the two risks in each difference. For example, L1_1 and L1_2 define the Treatment A and B risks in the first row of the differences table. In the Risk Differences table, the P1 and P2 columns show the individual risk estimates used in the difference. For example, the Treatment A and B risk estimates are 0.6212 and 0.7352. The estimated difference, -0.1141, appears in the Estimate column. To reverse the direction of the difference, specify the REVERSE option in the RISK statement. The standard error, significance test, and confidence interval for the difference are in subsequent columns:

The following statements fit the same model in PROC LOGISTIC. The easiest way to obtain risk estimates for the individual Treatments is using the LSMEANS statement as shown. The ILINK option adds the Mean column showing the risk estimates. The E option shows the coefficients on the model parameters that the LSMEANS statement uses to define the risks and is required for subsequent use of the NLMeans macro. Also required by NLMeans is the STORE statement to save the fitted model and the ODS OUTPUT statement to save the coefficients defining the risks. The NLMeans macro can then be called as shown to estimate the risk differences along with significance tests and confidence intervals. To estimate risk ratios (relative risks) rather than risk differences, specify options=ratio in the macro call. To reverse the direction of the difference (or ratio) specify options=reverse in the macro call:

proc logistic data=neuralgia;
   class Treatment Sex / param=glm;
   model Pain = Treatment Sex Age Duration;
   lsmeans treatment / e ilink;
   estimate 
     'A' intercept 1 treatment 1 0 0 sex 0 1
         age 70.05 duration 16.73333,
     'B' intercept 1 treatment 0 1 0 sex 0 1
         age 70.05 duration 16.73333,
     'P' intercept 1 treatment 0 0 1 sex 0 1
         age 70.05 duration 16.73333 / e ilink;
   ods output coef=c;
   store log;
   run;
%nlmeans(instore=log, coef=c, link=logit,
         title=Risk Differences)

In the results below, the first two tables show the coefficients defining the risks as used by the LSMEANS statement followed by the coefficients from the ESTIMATE statement. Following that are the risk estimates (Mean column) and risk difference estimates based on the LSMEANS statement, and then the same as produced by the ESTIMATE statement. The NLMeans macro produced both sets of risk differences. Note that the coefficients that define the risks from the RISK statement (above) match the coefficients used by the ESTIMATE statement producing the same risk estimates and differences. When comparing those coefficients to the coefficients used in the LSMEANS statement, you can see that the RISK statement defines each Treatment risk at the reference Sex level, M, while the LSMEANS statement defines the risks equally distributed across the two Sex levels. The RISK and LSMEANS statements both use the average values of continuous predictors. The risk estimates and estimated differences using the LSMEANS statement differ from those using the ESTIMATE or RISK statement because of this difference in the definitions of the risks.

__________

Note: If the model contains one or more interactions of continuous predictors, specify the AT MEANS option in the LSMEANS statement to match the risk definition used by the RISK statement.