Contents: |
Purpose / History / Requirements / Usage / Details / Limitations / See Also |

**NOTE: Beginning in SAS ^{®} 9.4M6 (TS1M6), a version of this macro is available in the SAS/STAT^{®} Autocall library and does not need to be downloaded and defined before use. To access features in more recent versions of the macro (see History), download and run as described in Usage below.**

*PURPOSE:*- Provide multiple comparisons (pairwise, sequential, or against a control) on the mean scale among the levels of an effect in a generalized linear model. More complex contrasts of means and ratios of pairs of means can also be estimated and tested.
*HISTORY:*- The version of the NLMeans macro that you are using is displayed in the log when you specify
**version**(or any string) as the first argument. For example:%nlmeans(version, ...)

The NLMeans macro always attempts to check for a later version of itself. If it is unable to do this (such as if there is no active Internet connection available), the macro will issue the following message in the log:

NOTE: Unable to check for newer version

The computations performed by the macro are not affected by the appearance of this message.

*Version**Update Notes*1.4 Added **where=**and**covdrop=**. Requires version 1.9 or later of the NLEST macro.1.3 Added **print**|**noprint**to**options=**. Added**null=**. Requires version 1.8 or later of the NLEST macro.1.04, 1.1 Store sets of results in data sets EST1, EST2, ... . Append all sets into a single results file using **options=append**. Version 1.1 is available in the SAS/STAT Autocall Library beginning in SAS 9.4M6 (TS1M6).1.03 Fix for LABEL variable in **contrasts=**data set.1.02 Minor fix to version printing. 1.01 A LABEL variable can optionally be included in the **contrasts=**data set.1.0 Initial coding *REQUIREMENTS:*- Base SAS
^{®}, SAS/STAT^{®}, and the NLEST/NLEstimate macro are required. Version 1.3 or later of the NLMeans macro requires version 1.8 or later of the NLEST macro. Version 1.4 or later of the NLMeans macro requires version 1.9 or later of the NLEST macro. *USAGE:*- Follow the instructions on the
**Downloads**tab of this sample to save the NLMeans macro definition. Follow similar instructions to download and define the NLEST/NLEstimate macro. Replace the text within quotation marks in the following statements with the locations of the NLMeans and NLEST/NLEstimate macro definition files on your system. In your SAS program or in the SAS editor window, specify these statements to define both macros and make them available for use:%inc "<location of your file containing the NLEST macro>"; %inc "<location of your file containing the NLMeans macro>";

After defining both macros, fit a generalized linear model and include one or more LSMEANS, SLICE, or ESTIMATE statements with the E option and save the model using the STORE statement. You can then call the NLMeans macro to compare means. See the

**Results**tab for examples.The following parameters are required when using the NLMeans macro. The necessary model information is provided to the macro by specifying either the

**instore=**parameter or both the**inest=**and**incovb=**parameters. If the modeling procedure provides a STORE statement for saving the fitted model,**instore=**is generally the better method for providing the model information.**instore=***item-store*- Specifies the fitted model that was saved using the STORE statement in the modeling procedure. The OUT= option in the STORE statement saves the model in a file known as an
*item store*. This is the preferred method for providing the required model information. However, if the modeling procedure does not offer the STORE statement, then you might be able to use**inest=**and**incovb=**instead. See "Limitations" below.

... or both of the following ...

**inest=***data-set-name*- Specifies the data set of parameter estimates saved using an ODS OUTPUT statement in the modeling procedure. The parameter estimates of the model should be stored in a variable named ESTIMATE in this data set. An error is issued if the ESTIMATE variable is not found. When
**inest=**is specified,**incovb=**must also be specified. The parameter vector in the**inest=**data set must be compatible with the covariance matrix in the**incovb=**data set. See "Compatibility error when using**inest=**and**incovb=**" below. **incovb=***data-set-name*- Specifies the data set containing the variance-covariance matrix of model parameters saved using an ODS OUTPUT statement in the modeling procedure. Typically, an option such as COVB is required in the modeling procedure to make this matrix available for saving. When
**inest=**is specified,**incovb=**must also be specified. The parameter vector in the**inest=**data set must be compatible with the covariance matrix in the**incovb=**data set. See "Compatibility error when using**inest=**and**incovb=**" below.

The following parameters are also required:

**coef=***data-set-name*- Specifies the data set of estimate coefficients saved using an ODS OUTPUT statement in the modeling procedure. The required table must first be produced by including the E option in the LSMEANS, SLICE, or ESTIMATE statement in the modeling procedure. The table name is typically Coef and can be saved in a data set by specifying:
ods output Coef=
*data-set-name*; **link=***link-function*- Specifies the link function used in the modeling procedure, typically in the LINK= option in the MODEL statement. Note that for models fit by PROC PROBIT which specifies the link with the DIST= option, specify
**link=probit**or**cumprobit**when DIST=NORMAL;**link=logit**or**cumlogit**when DIST=LOGISTIC; or**link=cll**or**cumcll**when DIST=EXTREME or GOMPERTZ.

The following parameters are optional:

**diff=***type <type>*...

where*type*is**all**,**seq**, or*number*- To estimate and test all pairwise differences of means, specify
**diff=all**. Sequential differences of means (μ1-μ2, μ2-μ3, ...) are provided when**diff=seq**. To obtain all differences with a control level, specify**diff=***number*, where*number*is the position of the control level in the ordered list of levels shown in the results from the modeling procedure. For example, if level A is the control in a variable whose levels are shown in the order A, B, C, then specify**diff=1**. When there are multiple sets of estimates from the modeling procedure (presented in multiple tables), such as when the SLICE / E SLICEBY= statement is used or when multiple LSMEANS /E, SLICE /E, or ESTIMATE /E statements are used, then you can either specify a single*type*to apply to all estimate sets, or a list of*types*to apply different*types*to the sets. If**diff=**is omitted, all pairwise differences are done for all sets (**diff=all**). **contrasts=***data-set-name*- Specifies an optional data of coefficients defining contrasts among the estimates in each set of estimates. The specified data set must contain a variable named SET and
*k*variables named K1, K2, ... , K*k*, where*k*is the number of Row variables in**coef=**data set. Optionally, a LABEL variable can be included to label each of the specified contrasts. For a given row in the data set, the value of SET indicates the set of estimates that the contrast in that row applies to. The SET value must match one of the values of the LMatrix variable in the**coef=**data set. The K variables correspond to the Row variables in the**coef=**data set which define each estimate. For multinomial models,*k*=*mf*where*m*is the number of estimates requested in each response function and*f*is the number of response functions. For**link=glogit**models,*k*=*mf*+*m*. The additional set of*m*variables correspond to the last response level. See the description of**options=ratio**for limitations on the contrast coefficients when mean ratios are desired. If**contrasts=**and**diff=**are both specified,**diff=**is ignored. **where=***condition*- Requires version 1.4 or later of the NLMeans macro and version 1.9 or later of the NLEST macro. Specifies an optional condition to subset the
**inest=**,**incovb=**, and**coef=**data sets.*Condition*is a valid expression for the WHERE statement and is useful when the input data sets were created using a BY statement or, in survey analysis, when the DOMAIN statement was used. **covdrop=***variable(s)*- Requires version 1.4 or later of the NLMeans macro and version 1.9 or later of the NLEST macro. Specifies one or more variables to be dropped from the
**incovb=**data set. This can be helpful when an error occurs indicating that the covariance matrix is incompatible with the parameter vector. That error is often caused by the presence of numeric variables in the**incovb=**data set that do not contain columns of the covariance matrix. **null=***value*- Requires version 1.3 or later of the NLMeans macro and version 1.8 or later of the NLEST macro. Specifies
*value*in the null hypothesis H0: f(μ)=*value*, where f(μ) is the function of means being tested and*value*is a numeric value. Scientific notation, such as 1E4, is not allowed. The default is**null=0**. **df=***value*- Specifies the degrees of freedom to be used in the tests and confidence intervals computed for the estimated functions.
*value*must be a non-zero, positive value. Scientific notation, such as 1E4 is not allowed. If omitted, large-sample Wald statistics are given. The degrees of freedom for testing a linear combination of parameters in a linear model would typically be the number of observations used in fitting the model minus the number of parameters estimated in the model – essentially, the error degrees of freedom. **alpha=***value*- Specifies the alpha level to be used in computing confidence limits. If omitted,
**alpha=0.05**. **title=***title-text*- Specifies a title for the table(s) of results. The
*title-text*must not contain quotes (" or '), ampersands (&), commas, or parentheses. If omitted,**title=**Nonlinear Function Estimate. **options=<JOINT|NOJOINT> <NAMES|NONAMES> <REVERSE|NOREVERSE> <RATIO|NORATIO> <DIFINFNS|DIFALL> <APPEND|NOAPPEND> <PRINT|NOPRINT>**- Use
**options=**to enable or disable any of several binary options.**JOINT**combines multiple sets of estimates into a single set before differencing or applying contrasts.**NAMES**displays the names of the model parameters used by the NLEST macro.**REVERSE**reverses the direction of differencing done by**diff=**.**REVERSE**is ignored when**contrasts=**is specified.**RATIO**requests estimation of ratios rather than differences of pairs of means.**RATIO**can be used with**diff=**or**contrasts=**, but with**contrasts=**each contrast must specify exactly one 1 coefficient to select the numerator, one -1 coefficient to select the denominator, and 0 coefficients otherwise. For multinomial models,**DIFALL**applies the differencing type specified in**diff=**across all estimates rather than within the response functions as done by**DIFINFNS**. This option is ignored for nonmultinomial models.**APPEND**merges results from all estimate sets into a single results data set named EST_ALL.**NOAPPEND**saves results sets in separate data sets (EST1, EST2, ...). The last results set is always saved in data set EST as well.**NOPRINT**suppresses display of the results table (but does not suppress the table of parameter names).**PRINT|NOPRINT**requires version 1.3 or later of the NLMeans macro and version 1.8 or later of the NLEST macro. If not specified,**options=nojoint nonames noreverse noratio difinfns noappend print**.

*DETAILS:*- The NLMeans macro can be used after fitting a generalized linear model (GLM) and estimating multiple linear combinations of model parameters, L
_{i}β, which are response means when the inverse of the GLM link function,*g*, is applied. That is, μ_{i}=*g*^{-1}(L_{i}β). GLMs can be fit by several SAS/STAT procedures including GENMOD, GLIMMIX, LOGISTIC, PROBIT, SURVEYLOGISTIC, and GEE. L_{i}β estimates are available using the LSMEANS, SLICE, and ESTIMATE statements in the modeling procedure. The ILINK option in these statements provides estimates of the means, μ_{i}. If the STORE statement is used to save the fitted model, these statements are also available at any time using PROC PLM.While the DIFF option in the LSMEANS and SLICE statements provide pairwise differences on the link scale, L

_{i}β-L_{j}β, differences on the mean scale, μ_{i}-μ_{j}, are not available. Similarly, in an ESTIMATE statement that defines a difference, L_{i}β-L_{j}β, the ILINK option applies the inverse of the link function to the difference, g^{-1}(L_{1}β-L_{2}β) rather than computing the difference of the inverse linked estimates g^{-1}(L_{1}β)-g^{-1}(L_{2}β) = μ_{i}-μ_{j}. The quantity g^{-1}(L_{1}β-L_{2}β) is generally only of interest in the case where the link function,*g*, is the log. In this case, the ILINK (or EXP) option estimates the ratio of means.Note that the NLMeans macro is not needed for models that use the identity link. This includes models fit by the REG, GLM, MIXED, or ORTHOREG procedures and others. For these models, differences of L

_{i}β are differences of μ_{i}. Consequently, the results of the DIFF option in the LSMEANS or SLICE statement, or the results of an ESTIMATE statement that defines a difference of L_{i}β directly provide the differences of μ_{i}. You can also use the LSMESTIMATE statement to estimate or test differences or contrasts of means.The NLMeans macro can be used to provide estimates and tests of differences of means, μ

_{i}-μ_{j}, ratios of means, μ_{i}/μ_{j}, or more complex contrasts of means, L_{i}μ_{i}. Standard errors are obtained using the delta method. To do this, you supply the saved model and a data set containing the coefficients, L_{i}, used by the LSMEANS, SLICE, or ESTIMATE statements. You also indicate the link function used in the model. The model is best saved using the STORE statement in the modeling procedure. The coefficients can be saved by including the E option in any LSMEANS, SLICE, or ESTIMATE statement specified in the procedure, and by including an ODS OUTPUT statement to save the displayed table of coefficients in a data set. In most cases, the name of the coefficients table is Coef, so the following statement saves it in a data set.ods output coef=

*data-set-name*;See the list of macro parameters above for details about how to provide the saved model and coefficients to the macro, about how to request means, ratios, or contrasts, and other options.

The macro can process more than one set of estimates. Multiple sets of estimates occur when the modeling procedure includes: a SLICE statement, multiple LSMEANS or ESTIMATE statements, or a combination of these statements. The macro processes each set and a table of results is displayed for each set of estimates. By default, the results from each set are saved in separate data sets named EST1, EST2, EST3, ... . Specify

**options=append**to create a single data set named EST_ALL of all results from all sets. If EST_ALL already exists, new results are appended to it. The last results set is also stored in data set EST.For ordinal multinomial models, the macro by default produces comparisons within each of the response functions. To do comparisons across all response functions, specify

**options=difall**. For nominal multinomial models (**link=glogit**), the macro produces comparisons within each of the response level probabilities. When specifying a**contrasts=**data set, each contrast (row) of the data set must contain coefficients for all estimates in all response functions (ordinal) or in all response levels (nominal).Since the LSMEANS and SLICE statements require GLM parameterized CLASS variables (PARAM=GLM in the CLASS statement), the NLEST/NLEstimate macro called by the NLMeans macro will typically display the following Warning message in this log. This Warning can be ignored.

WARNING: The final Hessian matrix is not positive definite, and therefore the estimated covariance matrix is not full rank and may be unreliable. The variance of some parameter estimates is zero or some parameters are linearly related to other parameters.

**Compatibility error when using inest= and incovb=**Specifying

**inest=**and**incovb=**instead of**instore=**is generally not necessary. If used, modifications of those data sets or use of**where=**and/or**covdrop=**might be needed to correct incompatible parameter vector and covariance matrix. In some cases, it might be necessary to use the NLEST macro directly rather than NLMeans.The

**incovb=**data set should have the same number of observations (rows) and variables (columns) as the number of rows in the**inest=**data set in order to be compatible. Otherwise, an error message is issued which indicates the relevant numbers of rows and columns. If the**incovb=**data set contains numeric variables other than those containing the covariance matrix, they should be removed in order to avoid a compatibility error. This can be done either by preprocessing the data set to remove the extraneous variables or by specifying them in**covdrop=**(requires version 1.4 or later of the NLMeans macro adn version 1.9 or later of the NLEST macro).#### BY group or domain processing

The NLMeans macro does not directly support BY group processing or processing of domains from a survey analysis. That is, it cannot process results from a modeling procedure that was run using a BY or DOMAIN statement. However, this capability can be provided by the RunBY macro which can run the NLMeans macro repeatedly for each of the BY groups or domains. Version 1.4 or later of the NLMeans macro, version 1.9 or later of the NLEST macro, and version 1.1 or later of the RunBY macro are required. See the RunBY macro documentation for details on its use. Additionally, you can use

**where=**to allow NLMeans to process the results of one BY group or domain by specifying an appropriate condition to select that BY group or domain. See the example titled "BY group processing, domain processing, and using**where=**" in the**Results**tab above. *LIMITATIONS:*- The NLMeans macro is not intended for use with survival models (LIFEREG, PHREG, SURVEYPHREG), models from PROC CATMOD, or from SAS/ETS
^{®}procedures. The macro cannot be used to compare means from zero-inflated models fit by PROC GENMOD.Some modeling procedures cannot provide the necessary covariance matrix for some models. Some procedures either do not have a STORE statement (such as PROC FMM) or do not save the necessary model information (such as PROC COUNTREG). In such cases, use

**inest=**and**incovb=**instead of**instore=**. When using**inest=**and**incovb=**, incompatibility of the parameter vector and covariance matrix can occur. See "Compatibility error when using**inest=**and**incovb=**" above.For some models, such as those fit by the GENMOD or GLIMMIX procedures, use of the LSMEANS, SLICE, or ESTIMATE statements in the PLM procedure is recommended rather than using those statements in the modeling procedure. Using those statements in PLM requires saving the fitted model using the STORE statement in the modeling procedure.

Note that the NLMeans macro cannot use coefficients produced by the LSMESTIMATE statement. The macro requires the coefficients that define the individual means.

*SEE ALSO:*- The NLMeans macro forms the expressions to be evaluated. It then calls the NLEST/NLEstimate macro to do the computations. See the NLEST/NLEstimate macro description for details. The Margins macro can also be used to estimate and test differences or contrasts of means. Unlike the NLMeans macro, the Margins macro can be used when one or more predictors in the model is not fixed.

These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.

These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.

In addition to the examples below, several more examples of using the NLMeans macro can be found in these notes:

- Estimating differences in probabilities with confidence interval
- Estimating rate differences (with confidence interval) using a Poisson model
- Estimating relative risks in a multinomial response model
- Estimating a relative risk (also called risk ratio, prevalence ratio)
- Estimating the difference in differences of means
- Estimating the risk (proportion) difference for matched pairs data with binary response

**EXAMPLE 1: Estimate the difference or ratio of group means in a log-linked gamma model**The example titled "Gamma Distribution Applied to Life Data" in the GENMOD documentation presents failure times of 201 machine parts from two manufacturers, denoted A and B. The following GENMOD statements fit the log-linked gamma model. The STORE statement saves the model in an item store for later use by the NLMeans macro. The LSMEANS statement with the ILINK option is used in PROC PLM to estimate the manufacturer means.

proc genmod data = lifdat; class mfg / param=glm; model lifetime = mfg / dist=gamma link=log; store out=gammod; run; proc plm restore=gammod; lsmeans mfg / e ilink diff exp; ods output coef=coeffs; run;

In the partial results below, the intercept, MFG

_{A}, and MFG_{B}estimated model parameters are shown in the "Analysis Of Maximum Likelihood Parameter Estimates" table. The values in the Estimate column in the "MFG Least Squares Means" table are the estimates of the linear combinations of model parameters, L_{i}β, defined in the "Coefficients for MFG Least Squares Means" table. This table of coefficients is produced by the E option and will be needed by the NLMeans macro. From this table it can be seen that the MFG="A" estimate, 6.1501, is the Row1 linear combination defined as 1*Intercept+1*MFG_{A}. Similarly for MFG="B". Note that since the linear predictor in this gamma model estimates the log gamma mean, linear combinations of the model parameters, such as those from the LSMEANS or ESTIMATE statement, also estimate the log gamma mean. Therefore, 6.1501 is the estimated log mean for manufacturer A. 6.1302 is the estimated log mean for manufacturer B. The ILINK option in the LSMEANS statement applies the inverse of the link function to the estimates. In this log-linked model, that means that the estimates are exponentiated. The resulting mean estimates are presented in the column labelled "Mean". The estimated mean lifetimes are 468.74 for manufacturer A and 459.51 for manufacturer B. The DIFF option computes the pairwise differences among the LS-mean estimates and presents them in the "Differences of MFG Least Squares Means" table. This produces a difference of the log means, or equivalently a log ratio of means, in the Estimate column (0.01989). The EXP option exponentiates this difference producing in an estimated ratio of means in the Exponentiated column (1.0201). Note that the EXP option also exponentiates the estimates in the "MFG Least Squares Means" table resulting in the Exponentiated column that reproduces the Mean column from the ILINK option in this case.Analysis Of Maximum Likelihood Parameter Estimates Parameter DF Estimate Standard

ErrorWald 95% Confidence Limits Wald Chi-Square Pr > ChiSq Intercept 1 6.1302 0.1043 5.9257 6.3347 3451.61 <.0001 MFG A 1 0.0199 0.1559 -0.2857 0.3255 0.02 0.8985 MFG B 0 0.0000 0.0000 0.0000 0.0000 . . Scale 1 0.8275 0.0714 0.6987 0.9800

Coefficients for MFG Least

Squares MeansParameter MFG Row1 Row2 Intercept 1 1 MFG A A 1 MFG B B 1

MFG Least Squares Means MFG Estimate Standard Error z Value Pr > |z| Mean Standard Error

of MeanExponentiated A 6.1501 0.1159 53.07 <.0001 468.74 54.3172 468.74 B 6.1302 0.1043 58.75 <.0001 459.51 47.9468 459.51

Differences of MFG Least Squares Means MFG _MFG Estimate Standard Error z Value Pr > |z| Exponentiated A B 0.01989 0.1559 0.13 0.8985 1.0201 The difference of the manufacturer means can be estimated by the NLMeans macro. Before using the macro, both the NLMeans macro and the NLEST/NLEstimate macro that it calls must be defined in your current SAS session. Use the %INCLUDE statements described in the Usage section of the Details tab.

With the macros defined, you can now can now call the NLMeans macro. The fitted model, saved by the STORE statement as gammod, is provided by

**instore=**and the data set of coefficients defining the LS-means and saved by the ODS OUTPUT statement is provided by**coef=**. The link function used for this model is the log function. By default,**diff=all**meaning that all pairwise differences will be computed. Since there are two estimates, there is only one difference to estimate. A title for the table of results is supplied by**title=**. Note that quotes should not be used in the title.%NLMeans(instore=gammod, coef=coeffs, link=log, title=Difference of MFG means)

The estimated difference in lifetime means is 468.74 - 459.51 = 9.2309 with 95% large-sample confidence interval (-132.77, 151.23). The Label column displays the contrast applied to the mean estimates showing that the computed difference is MFG

_{A}-MFG_{B}. Note that if the MFG_{B}-MFG_{A}difference is desired, then add**options=reverse**in the macro call.Difference of MFG means

Label Estimate Standard Error Wald Chi-Square Pr > ChiSq Alpha Lower Upper 1 -1 9.2309 72.4517 0.016233 0.8986 0.05 -132.77 151.23 The ratio of means can also be provided by the NLMeans macro. Since it is of interest to test that the ratio equals 1 rather than 0 (the default),

**null=1**is specified.%NLMeans(instore=gammod, coef=coeffs, link=log, options=ratio, null=1, title=Ratio of MFG means)

The Label (1 /1) indicates that the computed ratio is MFG

_{A}/MFG_{B}. If preferred, the reciprocal of this ratio can be estimated by adding**options=reverse**in the macro call.Notice that the estimated ratio, 1.0201, is identical to the estimate provided by the EXP option in the LSMEANS statement. The ratio does not significantly differ from 1, the null hypothesis value specified by

**null=1**(*p*=0.8995). A large-sample 95% confidence interval for the ratio is (0.7083, 1.3319).Ratio of MFG means

Label Estimate Standard Error Wald Chi-Square Pr > ChiSq Alpha Lower Upper 1 /1 1.0201 0.1591 0.015949 0.8995 0.05 0.7083 1.3319 The difference in manufacturer means can also be produced by using the NLEST/NLEstimate macro directly, though this requires writing the difference of means in terms of the model parameter estimates. This is illustrated in the Example in the Results tab of the NLEST/NLEstimate macro description.

**EXAMPLE 2: BY group processing, domain processing, and using where=**The NLMeans macro cannot process results from a modeling procedure that uses a BY or DOMAIN statement. However, the RunBY macro can be used to run the NLMeans macro on BY groups or domains in the saved results. To process a single BY group,

**where=**can be used. The capabilities shown below require version 1.4 or later of the NLMeans macro, version 1.9 or later of the NLEST macro, and version 1.1 or later of the RunBY macro.The following uses the insurance data that appears in the example titled "Poisson Regression" in the Getting Started section of the GENMOD documentation. The differences in age rates is to be estimated by car size using separate models fit to the data for each car size. These statements fit and save the models using the STORE statement. The rates for the AGE levels in each BY group (CAR) are estimated by the LSMEANS statement in the PLM procedure. The coefficients defining the LS-means are displayed by the E option and are saved by the ODS OUTPUT statement.

proc sort data=data.insure out=insure; by car; run; proc genmod data=insure; by car; class age; model c=age / dist=poisson offset=ln; store out=insmodel; run; proc plm restore=insmodel; lsmeans age / e ilink; ods output coef=coeffs; run;

#### Using where=

The following NLMeans macro call specifies a condition in

**where=**to select the large car model and estimate the difference in age rates in large cars.%NLMeans(instore=insmodel, coef=coeffs, link=log, where=car='large', title=Difference of age rates for large cars)

#### BY processing

The next statements process all of the BY groups using the RunBY macro. The NLMeans macro call is placed in the CODE macro and the condition in

**where=**is changed to use the special macro variables, _BYx and _LVLx. Since the BY groups are defined by the levels of the CAR variable in the INSURE data set,**data=insure**and**by=car**are specified in the RunBY macro call. The BYlabel macro variable is specified in**title=**in NLMeans to label the displayed results with the BY group definition.%macro code(); %NLMeans(instore=insmodel, coef=coeffs, link=log, where=&_BY1=&_LVL1, title=Difference of Age Rates &BYlabel) %mend; %RunBY(data=insure, by=car)

#### Domain processing

Domain analysis from the survey analysis procedures is similar to BY processing in that multiple models are fit to the domains identified in the DOMAIN statement. The following uses the data in the example titled "Domain Analysis" in the SURVEYREG documentation. Dichotomized versions of the body weight and age variables, BW2 and AGEGR, are created using the RANK procedure. The SURVEYLOGISTIC procedure then estimates a logistic model in each of the two domains identified by the two levels of the CANCER variable. The fitted models are saved using the STORE statement.

It is of interest to estimate the probability of low birthweight (BW2=0) in each age group and to estimate the relative risk (ratio) of these probabilities in each of the cancer domains. The probabilities are estimated by the ILINK option in the LSMEANS statement. It is necessary to specify the LSMEANS statement in the PLM procedure rather than directly in the survey analysis procedure in order to successfully apply the

**where=**condition. The coefficients defining the LS-means are displayed by the E option and are saved by the ODS OUTPUT statement.proc rank data=cancer groups=2 out=c2; var bodyweight age; ranks bw2 agegr; run; proc surveylogistic data=c2; class agegr/param=glm; strata strata; cluster psu; weight ObservationWt; model bw2(event="0") = agegr; domain cancer; store out=logdom; run; proc plm restore=logdom; lsmeans agegr / e ilink; ods output coef=c; run;

The following NLMeans macro call estimates the relative risk of the age probabilities in the cancer (CANCER=1) domain. The cancer domain is selected by the

**where=**condition. Specifying**options=ratio**requests computation of the ratio of estimated means from the LSMEANS statement, and**null=1**tests the null hypothesis that the relative risk equals 1.%NLMeans(instore=logdom, coef=c, where=cancer=1, link=logit, options=ratio, null=1, title=Relative Risk in cancer domain)

The relative risk can be computed for both domains by using the RunBY macro in the same way as for BY processing above.

%macro code(); %NLMeans(instore=logdom, coef=c, where=&_BY1=&_LVL1, link=logit, options=ratio, null=1, title=Relative Risk for &BYlabel) %mend; %RunBY(data=c2, by=cancer)

Right-click on the link below and select **Save** to save the NLMeans macro definition to a file. It is recommended that you name the file NLMeans.sas.

The LSMEANS, SLICE, and ESTIMATE statements in generalized linear modeling procedures such as GLIMMIX, GENMOD, LOGISTIC, and others provide mean estimates using the ILINK option, but estimates and tests of differences of means are not currently available. The NLMeans macro provides these and more.

#### Operating System and Release Information

Type: | Sample |

Topic: | Analytics ==> Regression SAS Reference ==> Macro |

Date Modified: | 2021-10-12 15:40:21 |

Date Created: | 2018-05-23 16:41:36 |

Product Family | Product | Host | SAS Release | |

Starting | Ending | |||

SAS System | SAS/STAT | Microsoft Windows 8 Enterprise 32-bit | ||

z/OS | ||||

z/OS 64-bit | ||||

OpenVMS VAX | ||||

Microsoft® Windows® for 64-Bit Itanium-based Systems | ||||

Microsoft Windows Server 2003 Datacenter 64-bit Edition | ||||

Microsoft Windows Server 2003 Enterprise 64-bit Edition | ||||

Microsoft Windows XP 64-bit Edition | ||||

Microsoft® Windows® for x64 | ||||

OS/2 | ||||

Microsoft Windows 8 Enterprise x64 | ||||

Microsoft Windows 8 Pro 32-bit | ||||

Microsoft Windows 8 Pro x64 | ||||

Microsoft Windows 8.1 Enterprise 32-bit | ||||

Microsoft Windows 8.1 Enterprise x64 | ||||

Microsoft Windows 8.1 Pro 32-bit | ||||

Microsoft Windows 8.1 Pro x64 | ||||

Microsoft Windows 10 | ||||

Microsoft Windows 95/98 | ||||

Microsoft Windows 2000 Advanced Server | ||||

Microsoft Windows 2000 Datacenter Server | ||||

Microsoft Windows 2000 Server | ||||

Microsoft Windows 2000 Professional | ||||

Microsoft Windows NT Workstation | ||||

Microsoft Windows Server 2003 Datacenter Edition | ||||

Microsoft Windows Server 2003 Enterprise Edition | ||||

Microsoft Windows Server 2003 Standard Edition | ||||

Microsoft Windows Server 2003 for x64 | ||||

Microsoft Windows Server 2008 | ||||

Microsoft Windows Server 2008 R2 | ||||

Microsoft Windows Server 2008 for x64 | ||||

Microsoft Windows Server 2012 Datacenter | ||||

Microsoft Windows Server 2012 R2 Datacenter | ||||

Microsoft Windows Server 2012 R2 Std | ||||

Microsoft Windows Server 2012 Std | ||||

Microsoft Windows Server 2016 | ||||

Microsoft Windows XP Professional | ||||

Windows 7 Enterprise 32 bit | ||||

Windows 7 Enterprise x64 | ||||

Windows 7 Home Premium 32 bit | ||||

Windows 7 Home Premium x64 | ||||

Windows 7 Professional 32 bit | ||||

Windows 7 Professional x64 | ||||

Windows 7 Ultimate 32 bit | ||||

Windows 7 Ultimate x64 | ||||

Windows Millennium Edition (Me) | ||||

Windows Vista | ||||

Windows Vista for x64 | ||||

64-bit Enabled AIX | ||||

64-bit Enabled HP-UX | ||||

64-bit Enabled Solaris | ||||

ABI+ for Intel Architecture | ||||

AIX | ||||

HP-UX | ||||

HP-UX IPF | ||||

IRIX | ||||

Linux | ||||

Linux for x64 | ||||

Linux on Itanium | ||||

OpenVMS Alpha | ||||

OpenVMS on HP Integrity | ||||

Solaris | ||||

Solaris for x64 | ||||

Tru64 UNIX |