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 1996, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Mon, 17 Jun 1996 09:18:16 +0200
Reply-To:   Jean Pierre Desgoutte <desgoutte@CEREQ.FR>
Sender:   "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:   Jean Pierre Desgoutte <desgoutte@CEREQ.FR>
Subject:   Re: Help on re-ordering variables in a dataset.

At 20:10 14/06/1996 GMT, you wrote: >I need to re-order the variables in a dataset, in order to import them >correctly > into a package that calaculates standard errors across repeated measures. My > experimentation using the KEEP statement and dataset option have been > unsuccessful. I can think of many ways to dump out the variables in little >chunks > and merge the 150 datasets back together in the proper order. It would be easy > to write a macro to handle the mess. > >Does anyone know of an easier way to re-order the variables in a SAS dataset, > using a data step statement, dataset option, etc. ??? > >Thanks in advance for your help..... > >Gordon Keeler, Statitician >gkeeler@psych.mc.duke.edu >Developmental Epidemiology >Dept. of Psychiatry >Duke University Medical Center >

This is one way to get what you want, using macro and proc contents.

%let in_data = YOUR_DATA; %let out_data = NEW_ONE; %let order = VARIABLE NAMES IN THE WANTED ORDER;

%macro vorder; %local i mot; %let i = 1; %let mot = %scan (&order, 1); %do %while (&mot ^=); &mot &&&mot %let i = %eval (&i + 1); %let mot = %scan (&order, &i); %end; %mend vorder;

proc contents data = &in_data noprint out = cont (keep = name type length); run;

data _null_; set cont; if type = 1 then call symput (name, put (length, best.)); else call symput (name, "$" || put (length, best.)); run;

data &out_data; length %vorder; set &in_data; run;

------------------------------------------------------------ Desgouttte Jean Pierre Email : desgoutte@cereq.fr Cereq Tel : (33) 91 13 28 01 10, Place de la Joliette Fax : (33) 91 13 28 80 BP 176 13474 Marseille cedex 02


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