When elements are initialized within an ARRAY statement the values are automatically retained from one iteration of the. DATA step to another; a RETAIN
The RETAIN statement allows values to be kept across observations enabling complex data manipulation. variables or members of an array.
At the beginning of the second iteration since data is read from an existing SAS dataset
SAS arrays can be used for simple repetitive tasks reshaping data Array names can be used in RETAIN statements
The SAS® documentation has devoted a significant section to the RETAIN statement explaining many This is a list of variables NOT comprising an array.
This paper introduces SAS® syntax to accomplish LOCF and demonstrates the use of RETAIN statement
A common data managing task for SAS® programmers is transposing data. is important to retain the array TEST in the DATA step; otherwise ...
and then Maybe Reset
+ Programmer Analyst in PPD. + Previously worked in a local bank as a SAS programmer for. Marketing Analytics. + Attended a 3-month SAS Bootcamp Training
ARRAY statement). The values of retained variables are not set to a missing value for each iteration of the Data Step as are the values of non- retained
Basic Syntax of the ARRAY Statement To use arrays in SAS code first make sure that you understand the basic syntax of the SAS ARRAY statement This section describes the ARRAY statement and provides a number of examples to illustrate its use Subsequent sections progress to more complex statements and examples
SAS ARRAY is a set of variables of the same type called “elements” of the arry that you want to perform the same operation on An array name is assigned to the set of variables Then the array name is reference in other DATA step programming to do an operation on the entire set of variables in the array
The RETAIN statement is often a mystery to beginning SAS programmers To understand how the RETAIN statement works you must first understand the basic operation of the SAS DATA step Program 1-1 demonstrates a SAS DATA step where a RETAIN statement is not used 1
The RETAIN statement is one method that SAS® programmers commonly use for making comparisons across observations One source of misunderstanding around the RETAIN statement centers around how long a value is retained and the ability or need to reset retained variables in many circumstances
SAS DO Loops and Why? SAS Array provides a different way to reference a group of variables Reference to the Array elements can be done using DO loops DO loop should have a corresponding END statement (Caution !) within a single DO loop multiple arrays can be referenced and operations on different arrays can be performed 6
the order of variables in a SAS dataset to meet external requirements • In summary the RETAIN statement can be used in novel ways to circumvent problems that commonly arise in the process of programming REFERENCES Gorrell Paul “The RETAIN Statement: One Window into the SAS Data Step"