Language Differences

For the most part, PROC MODEL programming statements work the same as they do in the DATA step as documented in SAS Language: Reference. However, there are several differences that should be noted.

DO Statement Differences

The DO statement in PROC MODEL does not allow a character index variable. Thus, the following DO statement is not valid in PROC MODEL, although it is supported in the DATA step:

   do i = 'A', 'B', 'C';  /* invalid PROC MODEL code */

IF Statement Differences

The IF statement in PROC MODEL does not allow a character-valued condition. For example, the following IF statement is not supported by PROC MODEL:

   if 'this' then  statement;

Comparisons of character values are supported in IF statements, so the following IF statement is acceptable:

   if 'this' < 'that' then  statement;

PROC MODEL allows for embedded conditionals in expressions. For example the following two statements are equivalent:

   flag = if time = 1 or time = 2 then conc+30/5 + dose*time
          else if time > 5 then (0=1) else (patient * flag);
   if time = 1 or time = 2 then flag= conc+30/5 + dose*time;
   else if time > 5 then flag=(0=1); else flag=patient*flag;

Note that the ELSE operator involves only the first object or token after it so that the following assignments are not equivalent:

   total = if sum > 0 then sum else sum + reserve;
   total = if sum > 0 then sum else (sum + reserve);

The first assignment makes TOTAL always equal to SUM plus RESERVE.

PUT Statement Differences

The PUT statement, mostly used in PROC MODEL for program debugging, supports only some of the features of the DATA step PUT statement. It also has some new features that the DATA step PUT statement does not support.

The PROC MODEL PUT statement does not support line pointers, factored lists, iteration factors, overprinting, the _INFILE_ option, or the colon (:) format modifier.

The PROC MODEL PUT statement does support expressions, but an expression must be enclosed in parentheses. For example, the following statement prints the square root of x:

   put (sqrt(x));

Subscripted array names must be enclosed in parentheses. For example, the following statement prints the ith element of the array A:

   put (a i);

However, the following statement is an error:

   put a i;

The PROC MODEL PUT statement supports the print item _PDV_ to print a formatted listing of all the variables in the program. For example, the following statement prints a much more readable listing of the variables than does the _ALL_ print item:

   put _pdv_;

To print all the elements of the array A, use the following statement:

   put a;

To print all the elements of A with each value labeled by the name of the element variable, use the following statement:

   put a=;

ABORT Statement Difference

In the MODEL procedure, the ABORT statement does not allow any arguments.

SELECT/WHEN/OTHERWISE Statement Differences

The WHEN and OTHERWISE statements allow more than one target statement. That is, DO groups are not necessary for multiple statement WHENs. For example in PROC MODEL, the following syntax is valid:

   select;
      when(exp1)
         stmt1;
         stmt2;
      when(exp2)
         stmt3;
         stmt4;
   end;

The ARRAY Statement

ARRAY arrayname < {dimensions} > < $ [length] > < variables and constants> ; ;

The ARRAY statement is used to associate a name with a list of variables and constants. The array name can then be used with subscripts in the model program to refer to the items in the list.

In PROC MODEL, the ARRAY statement does not support all the features of the DATA step ARRAY statement. Implicit indexing cannot be used; all array references must have explicit subscript expressions. Only exact array dimensions are allowed; lower-bound specifications are not supported. A maximum of six dimensions is allowed.

On the other hand, the ARRAY statement supported by PROC MODEL does allow both variables and constants to be used as array elements. You cannot make assignments to constant array elements. Both dimension specification and the list of elements are optional, but at least one must be supplied. When the list of elements is not given or fewer elements than the size of the array are listed, array variables are created by suffixing element numbers to the array name to complete the element list.

The following are valid PROC MODEL array statements:

   array x[120];           /* array X of length 120            */
   array q[2,2];           /* Two dimensional array Q          */
   array b[4] va vb vc vd; /* B[2] = VB, B[4] = VD             */
   array x x1-x30;         /* array X of length 30, X[7] = X7  */
   array a[5] (1 2 3 4 5); /* array A initialized to 1,2,3,4,5 */

RETAIN Statement

RETAIN variables initial-values ;

The RETAIN statement causes a program variable to hold its value from a previous observation until the variable is reassigned. The RETAIN statement can be used to initialize program variables.

The RETAIN statement does not work for model variables, parameters, or control variables because the values of these variables are under the control of PROC MODEL and not programming statements. Use the PARMS and CONTROL statements to initialize parameters and control variables. Use the VAR, ENDOGENOUS, or EXOGENOUS statement to initialize model variables.