Riccardo,
Actually it isn't important that you have them ordered in your data set at
all. SAS has var statements that takes care of any order you need such as
with proc print. The idea I believe is to free the programmer from having
to remember that and frees them up to concentrate on their program design
and output rather than the specifics. The same concept can be applied to
SAS's by statement.
data one ;
A_3 = 1 ;
A_1 = 2 ;
A_2 = 3 ;
run ;
data twob ;
set one ;
array A (3) ;
B = sum(of A_1--A_3) ;
put _all_ ;
run ;
Does throw an error. But consider this as an alternative:
data twoa ;
set one ;
B = sum(of A_1-A_3) ;
put _all_ ;
run ;
It throw no errors.
An een better solution given that your naming schema is the same and you
want all the vars starting with some predefined set of characters to be
summed is:
data twoc ;
set one ;
B = sum(of A: ) ;
put _all_ ;
run ;
Mmuch cleaner and you end up letting SAS to al the work. All the
programmer, program reader, and/or mainatance programmer need know is that
all vars starting with 'A_' will be summed.
Now there are some people who insist on a specified order (i.e. pointy
haired bosses). All that is required is a retain statement wit hthe order
you wish the vars to be held in the PDV. This question has come up so much
in the past I won't go into the specifics of how it works but will leave
those readers who are interested to go search the archives. The only thing
you have to remember is that you need to have the retain statement before
set statement or before you reference any other variables.
Data One ;
retain I_1 I_2 I_3 I_4 I_5 ;
set aaa ;
run ;
Will set I_1--I_5 as the first five vars in the PDV regardless of the order
of the vars read from the meta data coming from data set aaa.
Toby Dunn
From: riccardo <***@GMAIL.COM>
Reply-To: riccardo <***@GMAIL.COM>
To: SAS-***@LISTSERV.UGA.EDU
Subject: Re: Order to columns in SAS dataset..........
Date: Tue, 20 Dec 2005 06:29:22 -0800
Hi there
I understand it is important to have columns in a specific order....
also for specifing intervals by separating the first and last variable
with a double dash.
I work it around by writing a proc summary statement using the var
option to give the order you want.
Another way to do it is creating an empty table with the column order
wanted and then appending the data to this new table.
Any step that re-writes the PDV to the desired order might do....
Riccardo
Post by SaovikHow do you give order to columns in a SAS dataset..........? I am
having variables like i_: etc.... how do I deal with them while giving
order............?