Usage Note 8395: How to reorder variables in a SAS data set
Any of the following statements can be used to change the order of
variables in a SAS data set:
ATTRIB, ARRAY, FORMAT, INFORMAT, LENGTH, and RETAIN.
For any of these statements to have the desired effect, they must be
placed prior to a SET/MERGE/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 simply
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, if data set ONE has variables V W X Y Z (in that order)
you can reorder the variables to move Y as the first variable by doing
the following:
DATA ONE;
RETAIN Y;
SET ONE;
RUN;
After running this step, the variables in data set ONE are in the
order Y V W X Z.
Operating System and Release Information
| Product Family | Product | System | Reported Release | Fixed Release* |
| SAS System | Base SAS | Microsoft Windows 95/98 | 8 TS M0 | |
| OpenVMS VAX | 8 TS M0 | |
| Solaris | 8 TS M0 | |
| HP-UX | 8 TS M0 | |
| z/OS | 8 TS M0 | |
| 64-bit Enabled Solaris | 8 TS M0 | |
| OS/2 | 8 TS M0 | |
| CMS | 8 TS M0 | |
| 64-bit Enabled AIX | 8 TS M0 | |
| 64-bit Enabled HP-UX | 8 TS M0 | |
| Microsoft Windows NT Workstation | 8 TS M0 | |
| OpenVMS Alpha | 8 TS M0 | |
| Tru64 UNIX | 8 TS M0 | |
| AIX | 8 TS M0 | |
*
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.
| Date Modified: | 2003-06-18 15:20:46 |
| Date Created: | 2002-09-05 12:48:06 |