Help using Base SAS procedures

Proc Tabulate - Order by Statistic

Reply
Contributor
Posts: 61

Proc Tabulate - Order by Statistic

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!

Contributor
Posts: 61

Proc Tabulate - Order by Statistic

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;

SAS Super FREQ
Posts: 8,742

Re: Proc Tabulate - Order by Statistic

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
Ask a Question
Discussion stats
  • 2 replies
  • 241 views
  • 0 likes
  • 2 in conversation