BookmarkSubscribeRSS Feed
DME790
Pyrite | Level 9

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%

2 REPLIES 2
reshmape
Fluorite | Level 6

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'.

ballardw
Super User

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;

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 841 views
  • 0 likes
  • 3 in conversation