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 (May 2000, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Wed, 3 May 2000 10:17:09 -0400
Reply-To:   "Primak, Philip" <Philip.Primak@GENZYME.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Primak, Philip" <Philip.Primak@GENZYME.COM>
Subject:   Re: Most efficient way to chang variable order in data set
Comments:   To: Joel Winter <jpwinter@UMSL.EDU>

Hi Joel,

I used to have this problem before, and I could suggest two ways of reordering variables in PDV. Let's say that you have data set X with variables A, B, C and D and you want to create data set Y where variables will be ordered as D, C, B and A.

data x; a=1; b=2; c=3; d=4; run;

The first technique is to use RETAIN before SET:

data y; retain d c b a; set x; run;

The disadvantage of this approach is that you will have to reread you original data, what you do not want to do in general (you want just change order of variables in descriptor).

As an alternative I can suggest the following technique:

1. First run the following SQL : proc sql ; describe table x; quit;

2. Go to your log and copy the SAS code SQL created and paste it back to program editor: create table WORK.X( bufsize=4096 ) ( A num, B num, C num, D num );

3. Using copy and paste rearrange variables order proc sql; create table WORK.y( bufsize=4096 ) ( D num, C num, B num, A num ); quit;

4. Run the above code with the following PROC APPEND proc append base=y data=x;run;

The idea behind this is that does not matter how big is your original data set in steps 1, 2 and 3 you are working and creating just descriptor portion. Appending data works more efficient then DATA-SET syntax which require rereading the entire data.

Hope this would help. Good luck!

Philip Primak Genzyme Corporation

-----Original Message----- From: Joel Winter [mailto:jpwinter@UMSL.EDU] Sent: Tuesday, May 02, 2000 9:18 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Most efficient way to chang variable order in data set

Hi all,

I received a quite large data set (> 3000 cases, > 2000) variables. I would like to chop things down to a more manageable size.

The variables represent survey items. Numbering for survey items is somewhat akward (eg, q1 q2 q2a q2oth q3). Plus, the variable ordering in the data set is off from the ordering on the surveys. I would like to get the order back to the survey ordering, so that I can safely use variable ranges (eg, q1--q3).

The variable are a mix of numeric and string, and have labels.

Any suggestions are greatly appreciated.


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