03-13-2017 01:24 PM
I met a question here:
I have a dataset with 32 rows (not columns), and I want to change the order of rows by what I want. for example, if I have the dataset with order:
But I want the row order like:
any way can solve this?
03-13-2017 01:40 PM
You said that those values were all in the same column, but on different rows. If it's a SAS dataset, the column has to have a name.
If that doesn't answer your question, post an example of your file as a SAS data step.
Art, CEO, AnalystFinder.com
03-13-2017 01:42 PM
HAVE ==== Up to 40 obs WORK.HAVE total obs=4 Obs GRP 1 gender 2 age 3 lab1 4 lab2 WANT ==== Up to 40 obs WORK.WANT total obs=4 Obs GRP 1 age 2 lab1 3 lab2 4 gender FULL SOLUTION ============= * create some data; data have; input grp $; cards4; gender age lab1 lab2 ;;;; run;quit; proc format; value $grp2odr 'age' = '01' 'lab1' = '02' 'lab2' = '03' 'gender' = '04' ;run;quit; proc sql; create table want as select * from have order by put(grp,$grp2odr.) ;quit;
03-13-2017 02:26 PM
I think the better approach is with informat and formats, but just strictly with respect to the question of whether you can get what you want with the data you have, you can do an order by in proc sql where you sort on a boolean value first to force the order you want:
data have; input var $; datalines; gender age lab1 lab2 ; proc sql; CREATE TABLE want AS SELECT * FROM have ORDER BY var eq 'gender', var; quit;