Hi I have a dataset in sas like this:
ColA ColB ColC
Red 6 10
Blue 5 24
Average 4 5
Orange 4 10
Purple 4 11
I have to sort this data by colB in a way that "average" would be the last row like this. If I do this in usual way using "proc sort by colB" procedure, the average remains at the same place.
ColA ColB ColC
Red 6 10
Blue 5 24
Orange 4 10
Purple 4 11
Average 4 5
I would appreciate your help and suugestions and regarding the same.
Thanks.
Hi,
I modified my code after I saw Tom's code. Thank you Tom! I have learned a lot from you.
data have;
input ColA $ : ColB : ColC;
cards;
Red 6 10
Blue 5 24
Average 4 5
Orange 4 10
Purple 4 11
;
data temp;
set have;
if upcase(ColA)='AVERAGE' then group=2;
else group=1;
proc sort data=temp out=want(drop=group);
by descending colb group;
run;
proc print;run;
Obs ColA ColB ColC
1 Red 6 10
2 Blue 5 24
3 Orange 4 10
4 Purple 4 11
5 Average 4 5
Linlin
You probably want to create another variable to allow the average to be in its own group.
if colA='average' then group=2;
else group=1;
....
proc sort;
by group colA ....
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.