Desktop productivity for business analysts and programmers

Ordering in a proc Report

Reply
Frequent Contributor
Posts: 108

Ordering in a proc Report

Hi All,

 

I would like to order/sort in a proc report based on a computed column (TransPCT).

 

Any help appreciated  - cheers

 Dean

 

data test;
	Input Origin $ Target_Cluster $	Target_Code $ TransCount;
	Datalines;
AA DDD 1A 97
BB DDD 1B 1
CC EEE 2A 55
DD FFF 3A 1
EE FFF 3B 2
FF FIS 4A 1
GG OTH 5A 1
HH OTH 5B 1
II TPD 6A 2
JJ TPD 6B 1
;
Run;

Proc Report data=Test; Column ORIGIN TARGET_CLUSTER TARGET_CODE TRANSCOUNT TransPCT; Define Origin / DISPLAY ; Define Target_Cluster / DISPLAY 'Target Cluster'; Define Target_CODE / DISPLAY 'Target Queue'; Define TRANSCOUNT / DISPLAY 'Count' Analysis sum; Define TransPCT / Computed 'Percent' f=percent8.2; Compute Before; TransTOT = TransCount.SUM; ENDCOMP; compute TransPCT; TransPCT = TransCount.SUM / TransTOT; ENDCOMP; Rbreak after / Summarize; RUN;

 Current output looks like this

OriginTarget ClusterTarget QueueCountPercent
AADDD1A9759.88%
BBDDD1B10.62%
CCEEE2A5533.95%
DDFFF3A10.62%
EEFFF3B21.23%
FFFIS4A10.62%
GGOTH5A10.62%
HHOTH5B10.62%
IITPD6A21.23%
JJTPD6B10.62%
   162100.00%

 

Output required

OriginTarget ClusterTarget QueueCountPercent
AADDD1A9759.88%
CCEEE2A5533.95%
EEFFF3B21.23%
IITPD6A21.23%
BBDDD1B10.62%
DDFFF3A10.62%
FFFIS4A10.62%
GGOTH5A10.62%
HHOTH5B10.62%
JJTPD6B10.62%
   162

100.00%

New Contributor
Posts: 4

Re: Ordering in a proc Report

Hi,

I think we use proc report mainly for reporting the data.If you want to sort the data better to create a data set for finding TransPCT

and sort it by 'descending TransPCT'.

Super User
Posts: 12,996

Re: Ordering in a proc Report

Proc Report builds the output left to right per the columns in the column statement. If the major sort order is to be TransPCT it would have to be the first column.

 

Order variables (to control sorting) have to be dataset variables. So to accomplish what you want you would need to calculate transpct before proc report. At which point you could likely calculate transtot as well.

 

Or possibly consider:

proc freq data=test order=freq noprint;
   tables Origin* Target_Cluster*	Target_Code/list  out=work.sum;
   weight transcount;
run;

and use WORK.SUM as the input to proc report. The order is already correct.

 

or Proc print with the sum option

 

proc print data=work.sum noobs label;
   sum count percent;
run;
Ask a Question
Discussion stats
  • 2 replies
  • 133 views
  • 0 likes
  • 3 in conversation