Using More Than One Observation in a Calculation |
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.
information about DO groups can be found in Finding Shortcuts in Programming.
Another example of using the END= option in the SET statement is presented in Conditionally Processing Observations from Multiple SAS Data Sets.
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.
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.
The SUMMARY and MEANS procedures, which can also be used to compute totals are documented in the Base SAS Procedures Guide.
Copyright © 2012 by SAS Institute Inc., Cary, NC, USA. All rights reserved.