Creating Variables |
Accumulating
Totals |
To create a variable that accumulates values down observations, you can use a sum statement in your DATA step. |
General form, sum statement:
variable+expression; where
|
The sum statement adds the result of the expression on the
right side of the plus sign (+) to the numeric variable on the left side
of the plus sign. Then the sum statement retains the new value for use in
subsequent observations.
To find the total dollar amount for loan payments, you need a variable (in
this example, |
TotalLoan = | Payment + | previous total |
---|---|---|
0.00 | ||
467.43 = | 467.43 + | 0.00 |
1426.00 = | 958.57 + | 467.43 |
1751.02 = | 325.02 + | 1426.00 |
2059.54 = | 308.52 + | 1751.02 |
2463.01 = | 403.47 + | 2059.54 |
2856.08 = | 393.07 + | 2463.01 |
In your DATA step, you create
Finance.Newloan from Finance.Records. The
variables Amount and Rate are dropped because they
are not needed in the new data set. To create the total amount for loan payments,
you use the sum statement shown below:
data finance.newloan; set finance.records(drop=amount rate); TotalLoan+payment; run;
The value of the variable on the left of the plus sign (here,
|
Copyright © 2002 SAS Institute Inc.,
Cary, NC, USA. All rights reserved.