BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Max05
Obsidian | Level 7

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!

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Sort by MetricName MetricValue.

PG

View solution in original post

7 REPLIES 7
TomKari
Onyx | Level 15

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

Max05
Obsidian | Level 7
It is for my internship actually. I need to sort series of prices of multiple financial instruments composing a specific portfolio, and take the average to be able to calculate multiple risk measures such as VaR, CVaR, SRRI, etc.
Reeza
Super User

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.

Max05
Obsidian | Level 7

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 🙂 !!

PGStats
Opal | Level 21

Sort by MetricName MetricValue.

PG
Max05
Obsidian | Level 7

Thanks a lot!

novinosrin
Tourmaline | Level 20
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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1577 views
  • 1 like
  • 5 in conversation