Retained variables
What is a retained variable?A retained variable
The RETAIN statement
Retained variables are important especially in working with grouped observations. First we'll examine the concept with a simple example.
Example of a data step with a retained variabledata alpha; The output from proc print above would look like this:
A B C RUNTOT
2 4 6 12
3 1 5 21
0 7 9 37
8 5 4 54
How a retained variable behaves during data step executionTo understand the values of the retained variable RUNTOT on the output observations, picture the PDV during data step execution as follows. Before input a b c; is executed the first time: A B C RUNTOTAfter input a b c; is executed the first time: A B C RUNTOTAfter runtot=runtot + (a+b+c); is executed the first time: A B C RUNTOTAfter input a b c; is executed the second time: A B C RUNTOTAfter runtot=runtot + (a+b+c); is executed the second time: A B C RUNTOT
Another topic? Questions or comments? If you are affiliated with the Carolina Population Center, send them to Phil Bardsley.
|

