LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (February 2003, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Tue, 11 Feb 2003 09:35:37 +0100
Reply-To:   Peter Crawford <peter.crawford@DB.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Peter Crawford <peter.crawford@DB.COM>
Subject:   Re: Re-ordering the positions of columns
Comments:   To: glennu@TOTALISE.CO.UK
Comments:   cc: lpogoda <lpogodajr292185@COMCAST.NET>, EdHeaton@westat.com
Content-type:   text/plain; charset=iso-8859-1

As Lpogoda (lpogodajr292185@COMCAST.NET) points out "you might consider providing a view." I think that is a far more natural solution when the users of this "output" cannot see through to the underlying data. For any other situation, I think the sas system provides everything needed to show columns in any desired order ....without all this fuss about re-ordering storage of columns! "Column order" as requested, is the responsibility of the application which is used to display the columns, not the platform which offers the data. There are simple and sophisticated examples of my point. . In proc print, a var statement is available to present columns in (any) chosen order . In viewTable, a dataform entry is available to hold any preferred presentation order

Why disturb the "storage-logical" data order for the ephemeral interests of a sub-set of users ?

When the requirements of the data indicate a better order would be more "storage-logical" then _create_ the data in that order..............!!!

/glad-thats-off-my-chest ! /?0.02 off

Regards Peter Crawford

Datum: 11/02/2003 04:03 An: SAS-L@LISTSERV.UGA.EDU

Antwort an: lpogoda <lpogodajr292185@COMCAST.NET>

Betreff: Re: Re-ordering the positions of columns Nachrichtentext:

Ed Heaton wrote in message <9B501B3774931C469BCCCC021BE5372231E5C0@remailnt2-re01.westat.com>... >Glen, try this > >DATA test ; > Array x [*] Ed Nazik Bob Alla Ethel Bernadette ; > Stop ; >Run ; > >Proc contents data=test out=vars(keep=name) noPrint ; >Run ; > >Proc sql noPrint ; > Select > name into :orderedVars separated by " " > from vars > order by upCase(name) > ; > Drop vars ; >Quit ; > >Data new ; > Retain &orderedVars ; > Set test ; >Run ; >

In version 8, I've run into at least one case where using RETAIN this way does not reorder the variables in the resulting dataset. Since you're in PROC SQL anyway you might just as well use the dictionary tables to get the names of the variables in the first place and then continue on and use it to rewrite your dataset instead of using a DATA step, as in this tested code:

proc sql noprint ; select name into :orderedvars separated by ", " from dictionary.columns where lowcase(memname) = 'test' order by lowcase(name) ; create table new as select &orderedvars from test; quit;

But however it's done, I don't think it's very efficient to rewrite a dataset simply to reorder the variables, which is generally not required from a processing standpoint. If you simply must provide an ordered dataset for non-programming types to look at, you might consider providing a view. In that case, the above code would become:

proc sql noprint ; select name into :orderedvars separated by ", " from dictionary.columns where lowcase(memname) = 'test' order by lowcase(name) ; create view new as select &orderedvars from test; quit;

-----Original Message----- From: glenn [mailto:glennu@TOTALISE.CO.UK] Sent: Monday, February 10, 2003 12:34 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Re-ordering the positions of columns

Hi

I need to re-order the column positions of a dataset, so that the column position are in order according to the column names(ie. alphabetical order).

Does anyone know of a way/efficient way of doing this?

Any help would be greatly appreciated.

Cheers

Glenn

--

Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail ist nicht gestattet.

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.


Back to: Top of message | Previous page | Main SAS-L page