Any of the following statements can be used to change the order of the variables in a SAS data set:
ATTRIB
ARRAY
FORMAT
INFORMAT
LENGTH
RETAIN
In order for any of these statements to have the desired effect, they must be placed before a SET, MERGE, or UPDATE statement in the DATA step. All of these statements are declarative statements which are used in building the Program Data Vector (PDV) during the compilation phase of the DATA step.
Note that only the variables whose positions are relevant need to be listed in the above statements. Variables not listed in these statements retain their same positional order following the listed variables.
The RETAIN statement is most often used to reorder variables because no other variable attribute specifications are required. The RETAIN statement has no effect on retaining values of existing variables being read from the data set.
For example, there are six variables in data set ONE in the positional order of A, B, C, D, E, and F. If the new order needs to be A, E, C, D, B, and F, then the following DATA step reorders the variables in that order:
data two;
retain a e c d b;
set one;
run;
As noted, the variable F is left off the RETAIN statement since the order of variable F should not change. After running the above DATA step, the variables in data set ONE are in the order of A, E, C, D, B and F.
For more information, see What happens when the SET statement misbehaves—and how you can fix it!
Operating System and Release Information
| SAS System | Base SAS | 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 Enterprise 32-bit | | |
| Microsoft Windows 8 Enterprise x64 | | |
| Microsoft Windows 8 Pro 32-bit | | |
| z/OS | | |
| z/OS 64-bit | | |
| OpenVMS VAX | | |
| Microsoft Windows 8 Pro x64 | | |
| 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 | | |
| 64-bit Enabled HP-UX | | |
| Windows Vista for x64 | | |
| 64-bit Enabled AIX | | |
| Windows Vista | | |
| Windows 7 Ultimate x64 | | |
| Windows Millennium Edition (Me) | | |
| Windows 7 Ultimate 32 bit | | |
| Windows 7 Professional x64 | | |
| Windows 7 Home Premium x64 | | |
| Windows 7 Professional 32 bit | | |
| Windows 7 Home Premium 32 bit | | |
| Windows 7 Enterprise x64 | | |
| Microsoft Windows XP Professional | | |
| Windows 7 Enterprise 32 bit | | |
| Microsoft Windows Server 2012 Std | | |
| Microsoft Windows Server 2012 R2 Std | | |
| Microsoft Windows Server 2012 R2 Datacenter | | |
| Microsoft Windows Server 2008 for x64 | | |
| Microsoft Windows Server 2012 Datacenter | | |
| Microsoft Windows Server 2008 R2 | | |
| Microsoft Windows Server 2003 for x64 | | |
| Microsoft Windows Server 2008 | | |
| Microsoft Windows Server 2003 Standard Edition | | |
| Microsoft Windows Server 2003 Enterprise Edition | | |
| Microsoft Windows Server 2003 Datacenter Edition | | |
| Microsoft Windows 2000 Professional | | |
| Microsoft Windows NT Workstation | | |
| Microsoft Windows 2000 Server | | |
| Microsoft Windows 2000 Datacenter Server | | |
| Microsoft Windows 95/98 | | |
| Microsoft Windows 2000 Advanced Server | | |
| Microsoft Windows 8.1 Pro 32-bit | | |
| Microsoft Windows 8.1 Pro | | |
| Microsoft Windows 8.1 Enterprise 32-bit | | |
| Microsoft Windows 8.1 Enterprise x64 | | |
*
For software releases that are not yet generally available, the Fixed
Release is the software release in which the problem is planned to be
fixed.