<?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 to sort computed column variable? in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-to-sort-computed-column-variable/m-p/71595#M8205</link>
    <description>Thank you Cynthia! It was very helpful</description>
    <pubDate>Thu, 29 Jan 2009 02:28:46 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-01-29T02:28:46Z</dc:date>
    <item>
      <title>How to sort computed column variable?</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-to-sort-computed-column-variable/m-p/71593#M8203</link>
      <description>Can anyone help me if I want to sort a computed column variable in Proc Report? Thanks very much.

Message was edited by: htfdct</description>
      <pubDate>Wed, 28 Jan 2009 18:19:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-to-sort-computed-column-variable/m-p/71593#M8203</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-01-28T18:19:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort computed column variable?</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-to-sort-computed-column-variable/m-p/71594#M8204</link>
      <description>Hi:&lt;BR /&gt;
  You can only "sort" or "order" on group or order variables with PROC REPORT. A report item (what appears in the COLUMN statement) can only have one usage -- that means a usage of COMPUTED for a report item OR a usage of ORDER or GROUP, but not both usages.&lt;BR /&gt;
 &lt;BR /&gt;
  Your only choice is to create an output dataset (from PROC REPORT or another procedure) and then do your ordering on the computed variable. This example uses PROC REPORT to calculate projected sales for each product within each region and then uses the projected sales figure to control the order of the products within each region.&lt;BR /&gt;
&lt;BR /&gt;
  The first Proc Report is a summary report (without break lines) because all we want to do is get the projected sales item -and- the useord item for the next PROC REPORT. The next PROC REPORT just has a usage of ORDER for the region, useord and product report items because the data has already been summarized. &lt;BR /&gt;
&lt;BR /&gt;
You will see, if you run this program, that for every region, the products are now ordered by the descending projected sales -- which happened because the USEORD item appears in the column statement before the PRODUCT item. Since the USEORD item is assigned the NOPRINT attribute, the item will be used for ordering, but will not appear on the final report. The PROJ_SALES item has a SUM usage because we want to summarize it as a result of the BREAK statement.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc report data=sashelp.shoes nowd out=work.compord;&lt;BR /&gt;
  where region in ('Asia', 'Africa', 'Canada');&lt;BR /&gt;
  column region product sales proj_sales useord;&lt;BR /&gt;
  define region / group;&lt;BR /&gt;
  define product / group;&lt;BR /&gt;
  define sales / sum;&lt;BR /&gt;
  define proj_sales/computed;&lt;BR /&gt;
  define useord / computed;&lt;BR /&gt;
  compute proj_sales;&lt;BR /&gt;
     proj_sales=sales.sum * 1.15;&lt;BR /&gt;
  endcomp;&lt;BR /&gt;
  compute useord;&lt;BR /&gt;
     useord=proj_sales;&lt;BR /&gt;
  endcomp;&lt;BR /&gt;
run;&lt;BR /&gt;
                                       &lt;BR /&gt;
proc report data=work.compord nowd;&lt;BR /&gt;
  column region useord product sales proj_sales;&lt;BR /&gt;
  define region / order;&lt;BR /&gt;
  define useord / order descending noprint;&lt;BR /&gt;
  define product / order;&lt;BR /&gt;
  define sales /sum;&lt;BR /&gt;
  define proj_sales/ sum 'Projected/Sales/at 15%' f=dollar14.;&lt;BR /&gt;
  break after region / summarize;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Wed, 28 Jan 2009 20:43:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-to-sort-computed-column-variable/m-p/71594#M8204</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-01-28T20:43:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort computed column variable?</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-to-sort-computed-column-variable/m-p/71595#M8205</link>
      <description>Thank you Cynthia! It was very helpful</description>
      <pubDate>Thu, 29 Jan 2009 02:28:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-to-sort-computed-column-variable/m-p/71595#M8205</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-01-29T02:28:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort computed column variable?</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-to-sort-computed-column-variable/m-p/71596#M8206</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
When I run this example, why are the projected sales not in descending order (or any order)?&lt;BR /&gt;
The oseord column is in order (remove the no print), but not projected sales.&lt;BR /&gt;
&lt;BR /&gt;
Region useord Product Total Sales Projected&lt;BR /&gt;
218970.35 Sandal $190,409 $218,970 &lt;BR /&gt;
137810.25 Boot $119,835 $137,810 &lt;BR /&gt;
647213.1 Men's Casual $562,794 $647,213 &lt;BR /&gt;
480143.4 Women's Casual $417,516 $480,143 &lt;BR /&gt;
430454.2 Women's Dress $374,308 $430,454 &lt;BR /&gt;
387637.4 Slipper $337,076 $387,637 &lt;BR /&gt;
25472.5 Sport Shoe $22,150 $25,473 &lt;BR /&gt;
366275 Men's Dress $318,500 $366,275</description>
      <pubDate>Thu, 29 Jan 2009 13:51:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-to-sort-computed-column-variable/m-p/71596#M8206</guid>
      <dc:creator>BigD</dc:creator>
      <dc:date>2009-01-29T13:51:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort computed column variable?</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-to-sort-computed-column-variable/m-p/71597#M8207</link>
      <description>It is because the decimal point is shifted by BEST format.&lt;BR /&gt;
&lt;BR /&gt;
I suggest using order=internal.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
define useord / order descending noprint order=internal;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Thu, 29 Jan 2009 14:34:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-to-sort-computed-column-variable/m-p/71597#M8207</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-01-29T14:34:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort computed column variable?</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-to-sort-computed-column-variable/m-p/71598#M8208</link>
      <description>That's the ticket!</description>
      <pubDate>Thu, 29 Jan 2009 14:59:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-to-sort-computed-column-variable/m-p/71598#M8208</guid>
      <dc:creator>BigD</dc:creator>
      <dc:date>2009-01-29T14:59:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort computed column variable?</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-to-sort-computed-column-variable/m-p/71599#M8209</link>
      <description>Hi:&lt;BR /&gt;
  You don't actually need ORDER=INTERNAL. Just put a format in your PROC REPORT.&lt;BR /&gt;
&lt;BR /&gt;
  Here's the updated code and the results from each step are shown below it (changed the code to get only 2 regions for shorter posting).&lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc report data=sashelp.shoes nowd out=work.compord;&lt;BR /&gt;
  title '1) Make USEORD -- computed columns will be UNORDERED';&lt;BR /&gt;
  where region in ('Asia', 'Africa');&lt;BR /&gt;
  column region product sales proj_sales useord;&lt;BR /&gt;
  define region / group ;&lt;BR /&gt;
  define product / group;&lt;BR /&gt;
  define sales / sum  f=17.2;&lt;BR /&gt;
  define proj_sales/computed f=17.2;&lt;BR /&gt;
  define useord / computed f=17.2;&lt;BR /&gt;
  compute proj_sales;&lt;BR /&gt;
     proj_sales=sales.sum * 1.15;&lt;BR /&gt;
  endcomp;&lt;BR /&gt;
  compute useord;&lt;BR /&gt;
     useord=proj_sales;&lt;BR /&gt;
  endcomp;&lt;BR /&gt;
run;&lt;BR /&gt;
                                  &lt;BR /&gt;
proc print data=work.compord;&lt;BR /&gt;
  title '1a) Proc Print Before PROC REPORT';&lt;BR /&gt;
run;&lt;BR /&gt;
                                 &lt;BR /&gt;
proc report data=work.compord nowd nocenter;&lt;BR /&gt;
  column region useord product sales proj_sales;&lt;BR /&gt;
  title '2) Now ORDER with the USEORD column';&lt;BR /&gt;
  define region / order;&lt;BR /&gt;
  define useord / order descending f=17.2;&lt;BR /&gt;
  define product / order;&lt;BR /&gt;
  define sales /sum f=dollar17.2;&lt;BR /&gt;
  define proj_sales/ sum 'Projected/Sales/at 15%' f=dollar17.2;&lt;BR /&gt;
  break after region / summarize skip;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                    &lt;BR /&gt;
Output from the 1st PROC REPORT (#1) shows that every region is ordered by the alpha order of the PRODUCT (Boot comes first for both regions):&lt;BR /&gt;
[pre]&lt;BR /&gt;
1) Make USEORD -- computed columns will be UNORDERED&lt;BR /&gt;
                                                   &lt;BR /&gt;
  Region                     Product               Total Sales         proj_sales             useord&lt;BR /&gt;
  Africa                     Boot                    119835.00          137810.25          137810.25&lt;BR /&gt;
                             Men's Casual            562794.00          647213.10          647213.10&lt;BR /&gt;
                             Men's Dress             318500.00          366275.00          366275.00&lt;BR /&gt;
                             Sandal                  190409.00          218970.35          218970.35&lt;BR /&gt;
                             Slipper                 337076.00          387637.40          387637.40&lt;BR /&gt;
                             Sport Shoe               22150.00           25472.50           25472.50&lt;BR /&gt;
                             Women's Casual          417516.00          480143.40          480143.40&lt;BR /&gt;
                             Women's Dress           374308.00          430454.20          430454.20&lt;BR /&gt;
  Asia                       Boot                     62708.00           72114.20           72114.20&lt;BR /&gt;
                             Men's Casual             11754.00           13517.10           13517.10&lt;BR /&gt;
                             Men's Dress             119366.00          137270.90          137270.90&lt;BR /&gt;
                             Sandal                    8208.00            9439.20            9439.20&lt;BR /&gt;
                             Slipper                 152032.00          174836.80          174836.80&lt;BR /&gt;
                             Sport Shoe                2092.00            2405.80            2405.80&lt;BR /&gt;
                             Women's Casual           25837.00           29712.55           29712.55&lt;BR /&gt;
                             Women's Dress            78234.00           89969.10           89969.10&lt;BR /&gt;
                            &lt;BR /&gt;
[/pre]&lt;BR /&gt;
                               &lt;BR /&gt;
Output from the PROC PRINT (#1a) shows that the output dataset is in the same order as created in #1 by REPORT (Boot comes first for every region&lt;BR /&gt;
 -- nothing is ordered with USEORD yet -- although at this point, you could use PROC SORT on the file -- but that's unnecessary since PROC REPORT &lt;BR /&gt;
will do it in the next step):   &lt;BR /&gt;
[pre]&lt;BR /&gt;
1a) Proc Print Before PROC REPORT&lt;BR /&gt;
                                  &lt;BR /&gt;
                                                     proj_&lt;BR /&gt;
Obs    Region    Product                  Sales      sales        useord     _BREAK_&lt;BR /&gt;
                             &lt;BR /&gt;
  1    Africa    Boot                  $119,835    137810.25    137810.25&lt;BR /&gt;
  2    Africa    Men's Casual          $562,794    647213.10    647213.10&lt;BR /&gt;
  3    Africa    Men's Dress           $318,500    366275.00    366275.00&lt;BR /&gt;
  4    Africa    Sandal                $190,409    218970.35    218970.35&lt;BR /&gt;
  5    Africa    Slipper               $337,076    387637.40    387637.40&lt;BR /&gt;
  6    Africa    Sport Shoe             $22,150     25472.50     25472.50&lt;BR /&gt;
  7    Africa    Women's Casual        $417,516    480143.40    480143.40&lt;BR /&gt;
  8    Africa    Women's Dress         $374,308    430454.20    430454.20&lt;BR /&gt;
  9    Asia      Boot                   $62,708     72114.20     72114.20&lt;BR /&gt;
 10    Asia      Men's Casual           $11,754     13517.10     13517.10&lt;BR /&gt;
 11    Asia      Men's Dress           $119,366    137270.90    137270.90&lt;BR /&gt;
 12    Asia      Sandal                  $8,208      9439.20      9439.20&lt;BR /&gt;
 13    Asia      Slipper               $152,032    174836.80    174836.80&lt;BR /&gt;
 14    Asia      Sport Shoe              $2,092      2405.80      2405.80&lt;BR /&gt;
 15    Asia      Women's Casual         $25,837     29712.55     29712.55&lt;BR /&gt;
 16    Asia      Women's Dress          $78,234     89969.10     89969.10&lt;BR /&gt;
                           &lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                                       &lt;BR /&gt;
Output from the 2nd PROC REPORT (#2) shows that the USEORD column is now controlling the output. Essentially, you ignore #1 and #1a in your &lt;BR /&gt;
final report and only use #2 as the FINAL report. #1 and #1a are how you GET to #2 :&lt;BR /&gt;
[pre]&lt;BR /&gt;
                                                    &lt;BR /&gt;
2) Now ORDER with the USEORD column&lt;BR /&gt;
                                            &lt;BR /&gt;
                                                                                           Projected&lt;BR /&gt;
                                                                                               Sales&lt;BR /&gt;
  Region                                useord  Product               Total Sales             at 15%&lt;BR /&gt;
  Africa                             647213.10  Men's Casual          $562,794.00        $647,213.10&lt;BR /&gt;
                                     480143.40  Women's Casual        $417,516.00        $480,143.40&lt;BR /&gt;
                                     430454.20  Women's Dress         $374,308.00        $430,454.20&lt;BR /&gt;
                                     387637.40  Slipper               $337,076.00        $387,637.40&lt;BR /&gt;
                                     366275.00  Men's Dress           $318,500.00        $366,275.00&lt;BR /&gt;
                                     218970.35  Sandal                $190,409.00        $218,970.35&lt;BR /&gt;
                                     137810.25  Boot                  $119,835.00        $137,810.25&lt;BR /&gt;
                                      25472.50  Sport Shoe             $22,150.00         $25,472.50&lt;BR /&gt;
  Africa                                                            $2,342,588.00      $2,693,976.20&lt;BR /&gt;
                                                               &lt;BR /&gt;
  Asia                               174836.80  Slipper               $152,032.00        $174,836.80&lt;BR /&gt;
                                     137270.90  Men's Dress           $119,366.00        $137,270.90&lt;BR /&gt;
                                      89969.10  Women's Dress          $78,234.00         $89,969.10&lt;BR /&gt;
                                      72114.20  Boot                   $62,708.00         $72,114.20&lt;BR /&gt;
                                      29712.55  Women's Casual         $25,837.00         $29,712.55&lt;BR /&gt;
                                      13517.10  Men's Casual           $11,754.00         $13,517.10&lt;BR /&gt;
                                       9439.20  Sandal                  $8,208.00          $9,439.20&lt;BR /&gt;
                                       2405.80  Sport Shoe              $2,092.00          $2,405.80&lt;BR /&gt;
  Asia                                                                $460,231.00        $529,265.65&lt;BR /&gt;
                        &lt;BR /&gt;
[/pre]</description>
      <pubDate>Thu, 29 Jan 2009 16:47:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-to-sort-computed-column-variable/m-p/71599#M8209</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-01-29T16:47:10Z</dc:date>
    </item>
  </channel>
</rss>

