Previous Page | Next Page

Using More Than One Observation in a Calculation

Learning More

Automatic variable _N_

The automatic variable _N_, which provides a way to count the number of times SAS executes a DATA step, is discussed in Writing Lines to the SAS Log or to an Output File. Using _N_ is more efficient than using a sum statement. SAS creates _N_ in each DATA step. The first time SAS begins to execute the DATA step, the value of _N_ is 1; the second time, 2; and so on. SAS does not add _N_ to the output data set.

DO groups

information about DO groups can be found in Finding Shortcuts in Programming.

END= option

Another example of using the END= option in the SET statement is presented in Conditionally Processing Observations from Multiple SAS Data Sets.

KEEP= and DROP= data set options

see Starting with SAS Data Sets.

LAG family of functions

See SAS Language Reference: Dictionary. LAG functions provide another way to retain a value from one observation for use in a subsequent observation. LAG functions can retain a value for up to 100 observations.

RETAIN, SUM, and SET statements

See SAS Language Reference: Dictionary.

SUM and SUMBY statements

The SUM and SUMBY statements in the PRINT procedure are discussed in Producing Detail Reports with the PRINT Procedure. The SUM and SUMBY statements can be used in the PRINT procedure if the only purpose in getting a total is to display it in a report.

SUMMARY and MEANS procedures

The SUMMARY and MEANS procedures, which can also be used to compute totals are documented in the Base SAS Procedures Guide.

Previous Page | Next Page | Top of Page