Variables that are read by the SET, MERGE, and UPDATE statements are automatically retained between iterations of the data step. Variables that are created in the data set are not automatically retained and need the RETAIN statement if that behavior is desired.
The sample code provided shows the difference in retention between variables that are read from a data set and variables that are created within the data step. When the Program Data Vector (PDV) is created at compile time, variables that are read from a data set are marked for retention. That action holds true even if that variable is not read for a particular observation. Variables that are read from a data set are initialized to missing upon change of a by-group. Variables that are created within the data step are initialized to missing at the start of each iteration of the data step.
For more information, please see the section titled Data Step Processing in the SAS Language Reference: Concepts documentation.
Product Family | Product | System | SAS Release | |
Reported | Fixed* | |||
SAS System | Base SAS | Aster Data nCluster on Linux x64 | ||
DB2 Universal Database on AIX | ||||
DB2 Universal Database on Linux x64 | ||||
Greenplum on Linux x64 | ||||
Netezza TwinFin 32bit blade | ||||
Netezza TwinFin 32-bit SMP Hosts | ||||
Netezza TwinFin 64-bit S-Blades | ||||
Netezza TwinFin 64-bit SMP Hosts | ||||
Teradata on Linux | ||||
z/OS | ||||
Z64 | ||||
OpenVMS VAX | ||||
Microsoft® Windows® for 64-Bit Itanium-based Systems | ||||
Microsoft Windows Server 2003 Datacenter 64-bit Edition | ||||
Microsoft Windows Server 2003 Enterprise 64-bit Edition | ||||
Microsoft Windows XP 64-bit Edition | ||||
Microsoft® Windows® for x64 | ||||
OS/2 | ||||
Microsoft Windows 8 Pro | ||||
Microsoft Windows 95/98 | ||||
Microsoft Windows 2000 Advanced Server | ||||
Microsoft Windows 2000 Datacenter Server | ||||
Microsoft Windows 2000 Server | ||||
Microsoft Windows 2000 Professional | ||||
Microsoft Windows NT Workstation | ||||
Microsoft Windows Server 2003 Datacenter Edition | ||||
Microsoft Windows Server 2003 Enterprise Edition | ||||
Microsoft Windows Server 2003 Standard Edition | ||||
Microsoft Windows Server 2003 for x64 | ||||
Microsoft Windows Server 2008 | ||||
Microsoft Windows Server 2008 for x64 | ||||
Microsoft Windows Server 2012 | ||||
Microsoft Windows XP Professional | ||||
Windows 7 Enterprise 32 bit | ||||
Windows 7 Enterprise x64 | ||||
Windows 7 Home Premium 32 bit | ||||
Windows 7 Home Premium x64 | ||||
Windows 7 Professional 32 bit | ||||
Windows 7 Professional x64 | ||||
Windows 7 Ultimate 32 bit | ||||
Windows 7 Ultimate x64 | ||||
Windows Millennium Edition (Me) | ||||
Windows Vista | ||||
Windows Vista for x64 | ||||
64-bit Enabled AIX | ||||
64-bit Enabled HP-UX | ||||
64-bit Enabled Solaris | ||||
ABI+ for Intel Architecture | ||||
AIX | ||||
HP-UX | ||||
HP-UX IPF | ||||
IRIX | ||||
Linux | ||||
Linux for x64 | ||||
Linux on Itanium | ||||
OpenVMS Alpha | ||||
OpenVMS on HP Integrity | ||||
Solaris | ||||
Solaris for x64 | ||||
Tru64 UNIX |
/*Create a data set with name and score for each test.*/
data scores;
input name :$6. test score;
datalines;
Alice 1 84
Alice 2 93
Alice 3 100
Alice 4 65
;
/*Create a data set with the assigned level for name.*/
data levels;
input name :$6. level :$10.;
datalines;
Alice new
;
/* Merge the scores and levels to create new level values based on test score. */
/* Since the variable level is marked as being read from a data set, its value is */
/* retained throughout the by-group. After the third iteration of the Data step, level is */
/* set to "scholar" based on the IF statement. Since the variable level is retained, at */
/* the start of the fourth iteration, the value is still "scholar". Since the criteria for */
/* the IF statement is not met, there is no change made to the variable and it remains */
/* "scholar". */
/* Contrast this with the variable grade which is created in the Data step It is */
/* initialized to missing at the beginning of each iteration of the Data step. Thus, at the */
/* start of the fourth iteration, grade has been set to missing and since the criteria for */
/* the IF statement is not met, there is no new assignment made to the variable grade and */
/* it remains missing. */
data results;
merge scores levels;
by name;
if score > 92 then do;
level = 'scholar';
grade = 'A';
end;
run;
proc print;
run;
Obs name test score level grade 1 Alice 1 84 new 2 Alice 2 93 scholar A 3 Alice 3 100 scholar A 4 Alice 4 65 scholar
Type: | Usage Note |
Priority: | |
Topic: | Common Programming Tasks ==> Combining Data |
Date Modified: | 2012-11-15 16:00:38 |
Date Created: | 2012-10-13 14:43:12 |