Sum Statement


Adds the result of an expression to an accumulator variable

Valid: in a DATA step

Category: Action

Type: Executable

Syntax

variable + expression ;

Arguments

variable

  • specifies the name of the accumulator variable, which contains a numeric value.

  • Tip: The variable is automatically set to 0 before SAS reads the first observation. The variable s value is retained from one iteration to the next , as if it had appeared in a RETAIN statement.

  • Tip: To initialize a sum variable to a value other than 0, include it in a RETAIN statement with an initial value.

expression

  • is any SAS expression.

  • Tip: The expression is evaluated and the result added to the accumulator variable.

  • Tip: SAS treats an expression that produces a missing value as zero.

Comparisons

The sum statement is equivalent to using the SUM function and the RETAIN statement, as shown here:

 retain  variable  0;  variable  =sum(  variable  ,  expression  ); 

Examples

Here are examples of sum statements that illustrate various expressions:

  • balance+( ˆ’ debit);

  • sumxsq+x*x;

  • nx+(x ne .);

  • if status='ready' then OK+1;

See Also

Function:

  • SUM Function on page 843

Statement:

  • RETAIN Statement on page 1381




SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 704

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net