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

Hi all,

Have a 4 column data as below:

Michaelcwang2_0-1653035447278.png

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:

Michaelcwang2_1-1653035628368.png

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
ballardw
Super User

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.

View solution in original post

2 REPLIES 2
andreas_lds
Jade | Level 19

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.

ballardw
Super User

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.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is ANOVA?

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.

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