<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How can we sort data by PCT column from largest to smallest as it is computed column in proc rep in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-can-we-sort-data-by-PCT-column-from-largest-to-smallest-as/m-p/893414#M352934</link>
    <description>&lt;P&gt;Calculate the percentage in a preceding DATA step, so you can sort the result BY DESCENDING PCT.&lt;/P&gt;
&lt;P&gt;Then run PROC REPORT without the COMPUTE.&lt;/P&gt;</description>
    <pubDate>Sat, 09 Sep 2023 05:23:09 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-09-09T05:23:09Z</dc:date>
    <item>
      <title>How can we sort data by PCT column from largest to smallest as it is computed column in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-we-sort-data-by-PCT-column-from-largest-to-smallest-as/m-p/893413#M352933</link>
      <description>&lt;PRE&gt;&lt;CODE class=""&gt;TITLE height=3 color=BLUE J=LEFT "Branch Wise 1+ Count";
PROC REPORT DATA=WORK.FINAL_DPD LS=132 PS=60  SPLIT="/" CENTER ;
COLUMN  LOAN_BRANCH_BHEEM DPD TOTAL_COUNT PCT;
DEFINE  DPD / SUM FORMAT= 11. WIDTH=11    SPACING=2   CENTER "1+ Count" ;
DEFINE  LOAN_BRANCH_BHEEM / DISPLAY FORMAT= $150. WIDTH=150   SPACING=2   LEFT "Branch";
DEFINE 	TOTAL_COUNT / SUM CENTER "Total Count";
DEFINE  PCT/computed format = percent8.2 CENTER "% (Count)"; 

RBREAK AFTER/SUMMARIZE;
	COMPUTE AFTER;
	LOAN_BRANCH_BHEEM="Grand Total";
	if upcase(_BREAK_)="_RBREAK_" then do;
	call define (_row_,'style','style=[background=#EDF2F9 foreground=#112277 fontweight=bold');
	END;
	ENDCOMP;

	COMPUTE PCT; 
          PCT =_c2_/_c3_;           
	ENDCOMP;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 09 Sep 2023 05:14:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-we-sort-data-by-PCT-column-from-largest-to-smallest-as/m-p/893413#M352933</guid>
      <dc:creator>saikiran_nemani</dc:creator>
      <dc:date>2023-09-09T05:14:50Z</dc:date>
    </item>
    <item>
      <title>Re: How can we sort data by PCT column from largest to smallest as it is computed column in proc rep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-we-sort-data-by-PCT-column-from-largest-to-smallest-as/m-p/893414#M352934</link>
      <description>&lt;P&gt;Calculate the percentage in a preceding DATA step, so you can sort the result BY DESCENDING PCT.&lt;/P&gt;
&lt;P&gt;Then run PROC REPORT without the COMPUTE.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Sep 2023 05:23:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-we-sort-data-by-PCT-column-from-largest-to-smallest-as/m-p/893414#M352934</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-09-09T05:23:09Z</dc:date>
    </item>
    <item>
      <title>Re: How can we sort data by PCT column from largest to smallest as it is computed column in proc rep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-we-sort-data-by-PCT-column-from-largest-to-smallest-as/m-p/893418#M352936</link>
      <description>&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Grand Total&lt;/TD&gt;&lt;TD&gt;30053&lt;/TD&gt;&lt;TD&gt;196653&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt; as I am not able to get grand total against two columns as I am using display as an option.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Request to opinion on this.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Sat, 09 Sep 2023 06:03:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-we-sort-data-by-PCT-column-from-largest-to-smallest-as/m-p/893418#M352936</guid>
      <dc:creator>saikiran_nemani</dc:creator>
      <dc:date>2023-09-09T06:03:48Z</dc:date>
    </item>
    <item>
      <title>Re: How can we sort data by PCT column from largest to smallest as it is computed column in proc rep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-we-sort-data-by-PCT-column-from-largest-to-smallest-as/m-p/893423#M352940</link>
      <description>&lt;P&gt;Pleas post usable example data which leads to this expected outcome, so I can verify any code suggestions.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Sep 2023 06:55:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-we-sort-data-by-PCT-column-from-largest-to-smallest-as/m-p/893423#M352940</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-09-09T06:55:26Z</dc:date>
    </item>
    <item>
      <title>Re: How can we sort data by PCT column from largest to smallest as it is computed column in proc rep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-we-sort-data-by-PCT-column-from-largest-to-smallest-as/m-p/893429#M352944</link>
      <description>&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Location&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;30+ Count&lt;/TD&gt;&lt;TD&gt;Total Count&lt;/TD&gt;&lt;TD&gt;% (Count)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Kakinada&lt;/TD&gt;&lt;TD&gt;199&lt;/TD&gt;&lt;TD&gt;447&lt;/TD&gt;&lt;TD&gt;44.52%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Jaipur&lt;/TD&gt;&lt;TD&gt;315&lt;/TD&gt;&lt;TD&gt;768&lt;/TD&gt;&lt;TD&gt;41.02%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Visakhapatnam&lt;/TD&gt;&lt;TD&gt;136&lt;/TD&gt;&lt;TD&gt;354&lt;/TD&gt;&lt;TD&gt;38.42%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Maharasthra&lt;/TD&gt;&lt;TD&gt;133&lt;/TD&gt;&lt;TD&gt;362&lt;/TD&gt;&lt;TD&gt;36.74%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Karimnagar&lt;/TD&gt;&lt;TD&gt;139&lt;/TD&gt;&lt;TD&gt;418&lt;/TD&gt;&lt;TD&gt;33.25%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Grand Total&lt;/TD&gt;&lt;TD&gt;922&lt;/TD&gt;&lt;TD&gt;2349&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp; I am posting table which was asked earlier.&lt;/P&gt;&lt;P&gt;I have added datastep logic as per your suggestions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But everything comes right as it got sorted but Grand Total is not coming as I am expecting 30+ Count/Total Count.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Sep 2023 08:59:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-we-sort-data-by-PCT-column-from-largest-to-smallest-as/m-p/893429#M352944</guid>
      <dc:creator>saikiran_nemani</dc:creator>
      <dc:date>2023-09-09T08:59:10Z</dc:date>
    </item>
    <item>
      <title>Re: How can we sort data by PCT column from largest to smallest as it is computed column in proc rep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-we-sort-data-by-PCT-column-from-largest-to-smallest-as/m-p/893444#M352951</link>
      <description>&lt;P&gt;Add the calculation to the COMPUTE block:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;compute after;
  LOAN_BRANCH_BHEEM = "Grand Total";
  _c4_ = _c2_ / _c3_;
  if upcase(_BREAK_)="_RBREAK_" then do;
    call define (_row_,'style','style=[background=#EDF2F9 foreground=#112277 fontweight=bold');
  end;
endcomp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Just an idea, untested.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Sep 2023 17:15:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-we-sort-data-by-PCT-column-from-largest-to-smallest-as/m-p/893444#M352951</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-09-09T17:15:04Z</dc:date>
    </item>
    <item>
      <title>Re: How can we sort data by PCT column from largest to smallest as it is computed column in proc rep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-we-sort-data-by-PCT-column-from-largest-to-smallest-as/m-p/893449#M352954</link>
      <description>&lt;P&gt;That is not data, looks like perhaps the report?&lt;BR /&gt;So first let's convert it into actual data so we have something to program with.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input Location :$20. count total percent :percent.;
cards;
Kakinada  199 447 44.52%
Jaipur  315 768 41.02%
Visakhapatnam 136 354 38.42%
Maharasthra 133 362 36.74%
Karimnagar  139 418 33.25%
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now we can write PROC REPORT code.&amp;nbsp; You can use the PERCENT column twice.&amp;nbsp; Once to GROUP the report so you can use it to order and again so the value is displayed.&amp;nbsp; You can use COMPUTE AFTER block to add the GRAND TOTAL row label and also to fix up the percent.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=have;
  column percent location count total percent=x_percent ;
  define percent / group descending order=internal noprint;
  define location / group order=data ;
  define count / sum '30+ Count' format=comma7.;
  define Total / sum 'Total Count' format=comma7.;
  define x_percent / '% (Count)' format=percent8.2 ;
  rbreak after / summarize;
  compute after;
    location='Grand Total';
    x_percent = (count.sum/total.sum);
    call define (_row_,'style','style=[background=#EDF2F9 foreground=#112277 fontweight=bold');
  endcomp;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1694283932923.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/87745i686527A6D74703E6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1694283932923.png" alt="Tom_0-1694283932923.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;If you don't want the percent of 30+ day values on the Grand Total line then set it to missing instead.&amp;nbsp; You might want to set the system option MISSING to ' ' before hand so the value is not displayed as a period.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Sep 2023 18:27:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-we-sort-data-by-PCT-column-from-largest-to-smallest-as/m-p/893449#M352954</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-09T18:27:47Z</dc:date>
    </item>
  </channel>
</rss>

