Order columns in a data set.

Reply
Contributor
Posts: 30

Order columns in a data set.

My data set have variables VAR1, VAR2, and VAR3.

The variables are displayed in order VAR1, VAR3 and VAR2. I want them in order VAR1, VAR2 and VAR3.

How do I change the order in a DATA STEP?

Respected Advisor
Posts: 3,831

Re: Order columns in a data set.

Have a look into this very recent discussion

It's sometimes worth to first search the communities as a lot of questions have already been answered.

Trusted Advisor
Posts: 1,203

Re: Order columns in a data set.

data want;

retain var1 var2 var3;

set have;

run;

SAS Super FREQ
Posts: 3,406

Re: Order columns in a data set.

Often the order of variables does not matter, but I recently wrote an article about reordering variables according to a value of a statistic (mean, median, variance,...). Yes, I used the RETAIN statement. For details, see

Order variables by values of a statistic - The DO Loop

Ask a Question
Discussion stats
  • 3 replies
  • 190 views
  • 0 likes
  • 4 in conversation