Goodevening everyone 🙂
I would like to sort every columns of a dataset in ascending order INDEPENDENTLY.
From;
Weight Height Age
68 175 18
59 189 16
78 169 35
I would like to have
Weight Height Age
59 169 16
68 175 18
78 189 65
I really cant find a solution... Anyone for helping me?
Thanks in advance!
It's not that difficult, but this looks suspiciously like a homework assignment. Can you give us any insights into what you've tried, and what the business requirement for this could possibly be?
Tom
I think this is a case where you should restructure your data then.
Transpose it to a long format so that you have:
MetricName MetricValue
A 2
A 3
A 4
B 2
B 8
B 9
Then use a regular proc sort. Given your next steps this format will work better as well.
Hi Reeza,
First of all, thanks a lot for your answer. I managed to restructure my data to have that same structure as your example.
Then I tried the following code :
PROC SORT DATA=WORK.Prices
OUT=WORK.test;
BY MetricValue;
RUN;
PROC SQL;
CREATE TABLE WORK.QUERY_FOR_Prices AS
SELECT t1.MetricName,
t1.MetricValue
FROM WORK.Prices t1
ORDER BY t1.MetricValue;
QUIT;
Unfortunately, each time I obtain
A 2
B 2
A 3
A 4
B 8
Instead of
A 2
A 3
A 4
B 2
B 8
B 9
How can I adapt my code then? thank you very much 🙂 !!
Sort by MetricName MetricValue.
Thanks a lot!
data have;
input Weight Height Age ;
datalines;
68 175 18
59 189 16
78 169 35
;
data temp;
set have;
array t _numeric_;
do _n_=1 to dim(t);
k=t(_n_);
k1=vname(t(_n_));
output;
end;
run;
proc sort data=temp out=_temp;
by k1 k;
run;
proc transpose data=_temp(keep= k k1) out=want name=k1;
by k1;
var k;
run;
proc transpose data=want out=final_want(drop=_name_);
var col:;
id k1;
run;
proc tra
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.