ARCHIVED: In SAS, how do I reorder variables in a data set?

This content has been archived, and is no longer maintained by Indiana University. Information here may no longer be accurate, and links may no longer be available or reliable.

When you have existing data in SAS and want to change the order of the variables, use the retain statement. Suppose you have a data set mydata with variables in the order of e c a b d. To change the order to a b c d e, use the following code:

  data mydata;
   retain a b c d e;
   set mydata;
  run;

If you have questions about using statistical and mathematical software at Indiana University, contact the UITS Research Applications and Deep Learning team.

This is document baud in the Knowledge Base.
Last modified on 2023-05-09 14:44:06.