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

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.

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
  • 2 replies
  • 974 views
  • 0 likes
  • 2 in conversation