## Programming Statements

Although the most commonly used link and probability
distributions are available as built-in functions, the
GENMOD procedure enables you to define your own link
functions and response probability distributions using
the FWDLINK, INVLINK, VARIANCE, and DEVIANCE statements.
The variables assigned in these statements can
have values computed in programming statements.
These programming statements
can occur anywhere between the PROC
GENMOD statement and the RUN statement.
Variable names used in programming statements must be unique.
Variables from the input data set may
be referenced in programming statements.
The mean, linear predictor, and response are represented by
the automatic variables _MEAN_, _XBETA_, and _RESP_,
which can be referenced in your programming statements.
Programming statements are used to define the functional
dependencies of the link function, the inverse link
function, the variance function, and the deviance function
on the mean, linear predictor, and response variable.
The following code illustrates the use of programming statements.
Even though you usually request the Poisson distribution by
specifying DIST=POISSON as a MODEL statement option, you can
define the variance and deviance functions for the Poisson
distribution by using the VARIANCE and DEVIANCE statements.
For example, the following code performs the same analysis
as the Poisson regression example in the "Getting Started" section.

The code must be in logical order for
computation, just as in a DATA step.

proc genmod ;
class car age;
a = _MEAN_;
y = _RESP_;
d = 2 * ( y * log( y / a ) - ( y - a ) );
variance var = a;
deviance dev = d;
model c = car age / link = log offset = ln;
run;

The variables var and dev are dummy variables used internally by the
procedure to identify the variance and deviance functions.
Any valid SAS variable names can be used.

Similarly, the log link function and its inverse could
be defined with the FWDLINK and INVLINK statements.

fwdlink link = log(_MEAN_);
invlink ilink = exp(_XBETA_);

This code is for illustration, and it works
well for most Poisson regression problems.
If, however, in the iterative fitting process, the
mean parameter becomes too close to 0, or a 0 response
value occurs, an error condition occurs when the
procedure attempts to evaluate the log function.
You can circumvent this kind of problem by using
if-then-else clauses or other conditional statements
to check for possible error conditions and
appropriately define the functions for these cases.

Data set variables can be referenced in user
definitions of the link function and response distributions
using programming statements and the FWDLINK,
INVLINK,
DEVIANCE,
and VARIANCE statements.

See the DEVIANCE, VARIANCE, FWDLINK, and
INVLINK statements for more information.

Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.