BookmarkSubscribeRSS Feed
wcpatton
Calcite | Level 5

Any way this can be done?  Say I have a data set with segments and balances, I want to order the table by the sum of the balances.  I.e. the highest balance segment would be listed first.  Order=freq only would work if the balances are proportionate to the units. 

Thanks!

2 REPLIES 2
wcpatton
Calcite | Level 5

In this code, the resulting tabulate should rank C then A then B.

data one;

input seg $ bal;

datalines;

a 1

a 2

a 3

b 1

b 1

c 15

;

run;

proc tabulate data = one;

class seg /order=freq;

var bal;

tables seg ,

      bal = "Balance" *sum='' *f=comma24.0

;

run;

Cynthia_sas
SAS Super FREQ

Hi:

  What you want to do is easier to do with PROC REPORT than with PROC TABULATE. Neither REPORT nor TABULATE will order on a calculated statistic (such as your total for BAL), but you can "pre-summarize" the data and create a variable to be used as a "ordering" variable. PROC REPORT output, as shown in the attached screen shot will order on the data (which was ordered by descending ORDBAL in the SQL step. Then, after you understand how PROC REPORT is using the ORDBAL variable, it will also allow you to use the NOPRINT option to hide this ordering variable -- in my program, I have put a comment around the NOPRINT option.

cynthia


order_by_calc_sum.jpg

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1298 views
  • 0 likes
  • 2 in conversation