Use this example:
input var1 var2 var3;
1 2 4
1 4 4
4 3 6
7 5 9
title1 " data x1 ";
proc print data=x1;
/* in data x1 the order of variables is:
var1 var2 var3 */
/* suppose you wante them in oder:
var1 var3 var2 */
create table x2 as
select var1 ,var3, var2
title2 " data x2 ";
proc print data=x2;
From: Robert Abelson [mailto:rabelson@KAI-RESEARCH.COM]
Sent: March 15, 2002 4:28 PM
Subject: Re: How change variable's order in a sas dataset?
As I recall, at one time PROC SORT wouldn't work if any of the BY variables
was past a certain position in the dataset. That's when I first learned
about using RETAIN to reorder the variables in the dataset (around 1985
IIRC). Obviously, SAS has improved PROC SORT so that this is no longer the
6001 Montrose Rd.
Rockville, MD 20852
> -----Original Message-----
> From: Dianne Rhodes [SMTP:RHODESD1@WESTAT.COM]
> Sent: Friday, March 15, 2002 4:17 PM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Re: How change variable's order in a sas dataset?
> >IanWhitlock@westat.com wrote:
> > >Thus it is very likely that use of RETAIN to reorder
> >variables goes back to
> >the beginning of SAS.
> Yes, that is what I was taught in 1978.
> However some of the other features of RETAIN have changed a good bit.
> The statement that I learned was that RETAIN is not executable and can
> appear anywhere in the datastep. This is true, with the exception of
> Then the position matters.
> I recall that I frequently used this feature as a Research Assistant at
> Urban Institute (1980-1982) when I
> wanted to sort a large file on the MainFrame, to move the variable I was
> sorting on to the beginning of the file
> to make the sort run faster. That would have been at Dial Tyme under
> Dianne Louise Rhodes
> Sr. Systems Analyst