Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
It is usually straightforward to manipulate variables within a record. What is tricky is manipulating variables across records. SAS initializes each variable in a data set to missing when it starts to process a new observation. However, you might want SAS to remember a variable's value when it starts to process a new observation. The RETAIN statement achieves this objective. It is easier to understand the RETAIN statement when you see it in action.
The following example is based on a situation where individuals need to be tracked over time. These individuals are participating in a program where they receive services in the community. The individual can disenroll from the program at any time (say, when he or she is admitted to a hospital or nursing home). The individual can re-enroll at any time. For the example, a small data file is created. The data file has three individuals where individual 1 (id=1) has only one enrollment and disenrollment time. Individual two (id=2) has two enrollment and disenrollment times. Individual 3 (id=3) has three enrollment and disenrollment times. (The original data set on which this small data file is based is much more complicated. But, the small data file captures the flavor of the analysis.) Suppose you have the following goals: