Manoj Srivastava Manoj Srivastava - 1 year ago 53
SQL Question

sort columns in SAS

I have a data in individual columns in a table (Total) in SAS as below:

columnA ColumnB ColumnC ColumnD
20 30 10 50


I want to sort the columns in descending order of their values. i.e. the output should be as below :

columnD ColumnB ColumnA ColumnC
50 30 20 10


How to get the above output in SAS code?

DCR DCR
Answer Source

here you go:

data old;
a=20;
b=30;
c=10;
d=50;
run;

proc transpose data = old out=tran;
var _all_;
run;

proc sort data=tran out = sort;
by descending col1 ;
run;

proc transpose data = sort out=new (drop=_NAME_);
var col1;
id _NAME_;
run;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download