<?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: Proc Freq order=formatted not working (SAS EG (8.3.3.181) (64-bit)) in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Freq-order-formatted-not-working-SAS-EG-8-3-3-181-64-bit/m-p/792624#M81499</link>
    <description>Indeed. My misunderstanding of what it meant when I asked for "order = formatted".&lt;BR /&gt;&lt;BR /&gt;Thanks!</description>
    <pubDate>Wed, 26 Jan 2022 18:37:45 GMT</pubDate>
    <dc:creator>warrenschlechte</dc:creator>
    <dc:date>2022-01-26T18:37:45Z</dc:date>
    <item>
      <title>Proc Freq order=formatted not working (SAS EG (8.3.3.181) (64-bit))</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Freq-order-formatted-not-working-SAS-EG-8-3-3-181-64-bit/m-p/792307#M81481</link>
      <description>&lt;P&gt;I have followed Rick Wicklin's post about how to get Proc Freq to create tables in the order you want.&amp;nbsp; However, even though the data get sorted correctly, the output table is not displayed/sorted correctly.&amp;nbsp; Notice how when I printed the sorted dataset Cust "C" has all three gear types sorted correctly (Rod, Bow, Other); however, the output table using that variable (gearcat) and order=formatted, does not (instead output is alphabet).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My guess is this is because the first table value (Cust A) does not have all combinations of the second table variable (gearcat). I also tried using the "sparse" option in hopes that might help, but nothing changed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My question: how can I get Proc Freq to use the sorted order of the second variable if/when the first entry of the first variable doesn't contain a full compliment of the second variable?&amp;nbsp; I tried a hack where I gave every customer every gear, but with zero weights for those not in the "real" data, but that didn't help.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;/* Listing of Customers and Gears */

data test;
input Cust $ Gear $ ;
datalines;
A Bow
B Rod
C Bow
C Rod
C Other

;
run;

/* Create format that links Gear Categories in order to their labels */

proc format;
value gr
1='Rod'
2='Bow'
3='Other'
;
run;

/* Create numeric GearCat for sorting */
data test;
format gearcat gr.;
set test;
select (Gear);
when ('Rod') gearcat=1;
when ('Bow') gearcat=2;
when ('Other') gearcat=3;
when (' ') gearcat=.;
end;

/* Sort by Customer, then gearcat */

proc sort data=test; by cust gearcat;run;

proc print data=test;run; /* Shows the internal order is correct, see Customer C */

/* Create a 2-way table using order=formatted*/
/* Note how the order is wrong, even though the values were sorted properly */
/* Gearcat should be Rod - Bow - Other, not alphabetic */

proc freq data=test order=formatted;
tables cust*gearcat/nopercent nocol norow;
run;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Output.JPG" style="width: 291px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67811iC479B80D8B6BDD0A/image-size/large?v=v2&amp;amp;px=999" role="button" title="Output.JPG" alt="Output.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jan 2022 21:12:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Freq-order-formatted-not-working-SAS-EG-8-3-3-181-64-bit/m-p/792307#M81481</guid>
      <dc:creator>warrenschlechte</dc:creator>
      <dc:date>2022-01-25T21:12:23Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Freq order=formatted not working (SAS EG (8.3.3.181) (64-bit))</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Freq-order-formatted-not-working-SAS-EG-8-3-3-181-64-bit/m-p/792316#M81482</link>
      <description>&lt;P&gt;Since you replaced the text values with integers, just order the GEARCAT variable by the internal values 1,2,3. No need to sort:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc freq data=test order=internal;
tables cust*gearcat/nopercent nocol norow;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Jan 2022 20:47:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Freq-order-formatted-not-working-SAS-EG-8-3-3-181-64-bit/m-p/792316#M81482</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2022-01-25T20:47:47Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Freq order=formatted not working (SAS EG (8.3.3.181) (64-bit))</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Freq-order-formatted-not-working-SAS-EG-8-3-3-181-64-bit/m-p/792321#M81483</link>
      <description>&lt;P&gt;Thanks!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Still curious why the "formatted" option did not work, but pleased this does.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jan 2022 20:56:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Freq-order-formatted-not-working-SAS-EG-8-3-3-181-64-bit/m-p/792321#M81483</guid>
      <dc:creator>warrenschlechte</dc:creator>
      <dc:date>2022-01-25T20:56:40Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Freq order=formatted not working (SAS EG (8.3.3.181) (64-bit))</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Freq-order-formatted-not-working-SAS-EG-8-3-3-181-64-bit/m-p/792324#M81484</link>
      <description>&lt;P&gt;For gearcat, the raw values are 1,2,3 and the corresponding formatted values are {'Rod' 'Bow' 'Others'}. If you sort by the formatted values, you will get the order&amp;nbsp;'Bow' 'Others'&amp;nbsp;'Rod'.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jan 2022 21:04:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Freq-order-formatted-not-working-SAS-EG-8-3-3-181-64-bit/m-p/792324#M81484</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2022-01-25T21:04:30Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Freq order=formatted not working (SAS EG (8.3.3.181) (64-bit))</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Freq-order-formatted-not-working-SAS-EG-8-3-3-181-64-bit/m-p/792328#M81485</link>
      <description>&lt;P&gt;Partially a misunderstanding of the interaction between "formatted"&amp;nbsp; and the values you have specifically chosen. In FORMATTED order "Other" comes before "Rod" and "Bow" comes before "Other" because that is the sort order of the text values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your Sort doesn't use the formatted value of Gearcat, it uses the numeric value, so the formatted values have nothing to do with the Sort order displayed by Proc Print.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may want to consider looking at this with another procedure that allows more Order options:&lt;/P&gt;
&lt;PRE&gt;proc tabulate data=test;
   class gearcat /order=formatted;
   format gearcat gr.;
   class cust;
   table gearcat,
          cust
   ;
run;

proc tabulate data=test;
   class gearcat /order=data;
   format gearcat gr.;
   class cust;
   table gearcat,
          cust
   ;
run;

proc tabulate data=test;
   class gearcat /order=unformatted;
   format gearcat gr.;
   class cust;
   table gearcat,
          cust
   ;
run;
&lt;/PRE&gt;
&lt;P&gt;And for more fun, try changing your sort order around and then using this&lt;/P&gt;
&lt;PRE&gt;proc tabulate data=test;
   class gearcat /preloadfmt;
   format gearcat gr.;
   class cust;
   table gearcat,
          cust
         /printmiss
   ;
run;
&lt;/PRE&gt;
&lt;P&gt;In fact, you might try several sort orders with the previous.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jan 2022 21:24:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Freq-order-formatted-not-working-SAS-EG-8-3-3-181-64-bit/m-p/792328#M81485</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-01-25T21:24:44Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Freq order=formatted not working (SAS EG (8.3.3.181) (64-bit))</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Freq-order-formatted-not-working-SAS-EG-8-3-3-181-64-bit/m-p/792624#M81499</link>
      <description>Indeed. My misunderstanding of what it meant when I asked for "order = formatted".&lt;BR /&gt;&lt;BR /&gt;Thanks!</description>
      <pubDate>Wed, 26 Jan 2022 18:37:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Freq-order-formatted-not-working-SAS-EG-8-3-3-181-64-bit/m-p/792624#M81499</guid>
      <dc:creator>warrenschlechte</dc:creator>
      <dc:date>2022-01-26T18:37:45Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Freq order=formatted not working (SAS EG (8.3.3.181) (64-bit))</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Freq-order-formatted-not-working-SAS-EG-8-3-3-181-64-bit/m-p/792626#M81500</link>
      <description>Thanks. Between you and Ballardw I now better understand how my misunderstanding of "order=formatted" was causing my confusion.</description>
      <pubDate>Wed, 26 Jan 2022 18:39:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Freq-order-formatted-not-working-SAS-EG-8-3-3-181-64-bit/m-p/792626#M81500</guid>
      <dc:creator>warrenschlechte</dc:creator>
      <dc:date>2022-01-26T18:39:22Z</dc:date>
    </item>
  </channel>
</rss>

