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

## How to print data order by sum, not sort by variable?

Hi all,

Have a 4 column data as below:

And code as below:

```title1 'WORK.BINORI 的清單資料';

proc sort data=WORK.BINORI out=WORK.SORTTEMP;
by IBVEND;
run;

proc print data=WORK.SORTTEMP label;
by IBVEND;
sum COUNT;
id NORI;

run;```

And result as below:

NORI is binary as null or the 3 Chinese characters.

However try to print data in the order by sum of Count, not by sorted variable "IBVEND", appreciate any comment.

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

## Re: How to print data order by sum, not sort by variable?

Here is an example of @andreas_lds suggestion with a data set you should have available to test the code with.

```Proc summary data=sashelp.class nway;
class age;
var height;
output out=agesummary (drop= _type_ _freq_) sum=;
run;

proc sort data=agesummary;
by descending height;
run;

proc print data=agesummary noobs;
var age height;
run;

```

You could have more variables on the CLASS statement if needed for the groups, more than one output variable created and multiple statistics from the Proc Summary output. Then sort that resulting data set as desired.

2 REPLIES 2
Jade | Level 19

## Re: How to print data order by sum, not sort by variable?

Using BY in proc sort will always result in output being sorted by the variable(s) listed in the the statement. Instead of using proc sort + proc print, you could use proc summary + sort + print to get what you want.

Super User

## Re: How to print data order by sum, not sort by variable?

Here is an example of @andreas_lds suggestion with a data set you should have available to test the code with.

```Proc summary data=sashelp.class nway;
class age;
var height;
output out=agesummary (drop= _type_ _freq_) sum=;
run;

proc sort data=agesummary;
by descending height;
run;

proc print data=agesummary noobs;
var age height;
run;

```

You could have more variables on the CLASS statement if needed for the groups, more than one output variable created and multiple statistics from the Proc Summary output. Then sort that resulting data set as desired.

Discussion stats
• 2 replies
• 504 views
• 3 likes
• 3 in conversation