LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (June 2002, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 5 Jun 2002 14:28:17 -0400
Reply-To:     Ian Whitlock <WHITLOI1@WESTAT.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Ian Whitlock <WHITLOI1@WESTAT.COM>
Subject:      Re: retaining the order of variables
Comments: To: William Kossack <kossackw@NJC.ORG>
Content-Type: text/plain; charset="iso-8859-1"

William,

Suppose at some time you have data set A in the order you want it. Then use

data lib.Aord ; stop ; set A ; run ;

To capture this order without wasting space. Now some time further on you have a copy of A say Acopy. Then use

set lib.Aord Acopy ;

to reorder Acopy in the manner of Aord. Of course if you have the original copy of A then you can use

set A ( obs = 0 ) Acopy ;

and forget the first step. One advantage of this solution is that it not only saves the order, it also preserves labels, format information, and variable type and length. If this is perceived as disadvantage then use a RETAIN statement at the top of your DATA step.

The above answers the direct question asked. But it may not be the best answer to the problem. Remember the problem was that you have groups of variables and you want to preserve the groups. Order is one way, but not the only one. It is probably better to set up your groups one with code like

%let grpA = a b c ; %let grpB = r s t u v w ; ...

Store the code in a file and include it in any programs that need to know about these groups. Now you don't need to worry about order and can do anything you could do before with order. Moreover, anyone can know how you see the groupings and therefore have a better understanding of how to maintain your code. Another big advantage is that the initial files do not have to hold a whole group. For example, A could come from one file while B and C come from another. After merging I can still think about using &GRPA.

For example, suppose the problem is to produce cross tabs of all variables in grpA with those in grpB. Then the tables statement could be

table ( &grpA ) * ( &grpB ) ;

while using order one would have

table ( a--c ) * ( r--w ) ;

Now that one has long names for variables another solution would be to name the variables with a prefix indicating the group, GRPA_ or GRPB_. In this case there is no include file to consider and the table statement is

table ( GRPA: ) * ( GRPB: ) ;

Note that with wise choices for the group names the first and third TABLE statements make very clear what is going on, while there is no clue in second TABLE statement unless the variable names happen to be more wisely chosen than usual.

IanWhitlock@westat.com

-----Original Message----- From: William Kossack [mailto:kossackw@NJC.ORG] Sent: Wednesday, June 05, 2002 12:30 PM To: SAS-L@LISTSERV.UGA.EDU Subject: retaining the order of variables

I am doing manipulations of a large number of variables using merge statements and processing block of similar variables together.

I've discovered that I have reordered my variables which I don't like.

Is there a way of capturing the variable order of variables in a dataset and forcing the dataset to maintain that order?


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