<?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 PROC TABULATE order with format using a [format.] label in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-TABULATE-order-with-format-using-a-format-label/m-p/585897#M23241</link>
    <description>&lt;P&gt;I'm trying to run a tabulation where I run a bunch of single variable tables, with each variable having a custom format that is saved (notsorted) and defining the desired order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For categorical (discrete) variables this works well; using the solution in&amp;nbsp;&lt;A href="http://support.sas.com/kb/23/847.html" target="_blank"&gt;http://support.sas.com/kb/23/847.html&lt;/A&gt;&amp;nbsp;where we save the format with (notsorted) and use order=data on the tabulate (or on the class statement), everything is in order the way I want it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, for the continuous variables, we have a format that uses [best8.] as the default format, but with specific values cut out that I want to display at the bottom (imagine - values 6 and 9 have a special meaning and should go to the end).&amp;nbsp; This does not seem to work with the above solution - even if I treat it like a categorical in fact, if I use the [best8.] value anywhere in the format it fails to use the correct sorting and instead shows up as the dataset order (the normal meaning of order=data ignoring the format).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example.&amp;nbsp; It works fine with the 'y' variable, which is categorical, but with the 'x' continuous variable it will not sort properly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to make this work? Is this a bug, or expected functionality?&amp;nbsp; Maybe there's a better way for me to do the format that will work?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc format;
  value xf (notsorted)
   1-5=[best8.]
   7-8=[best8.]
   10=[best8.]
   9="Next to Bottom"
   6="Bottom"
 
   ;
  value yf   (notsorted)
  0 = "Top"
  1 = "Middle"
  2 = "Bottom"
  ;
  
  quit;
  
data test;  
  call streaminit(7);
  do x = 1 to 10;
    z = rand('uniform');
    y = mod(x,3);
    output;
  end;
  format x xf. y yf.;
run;

proc sort data=test;
  by z;
run;
 
%let var=x;
proc tabulate order=data;
  class &amp;amp;var./ preloadfmt;
  tables &amp;amp;var.,n;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 03 Sep 2019 17:41:14 GMT</pubDate>
    <dc:creator>snoopy369</dc:creator>
    <dc:date>2019-09-03T17:41:14Z</dc:date>
    <item>
      <title>PROC TABULATE order with format using a [format.] label</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-TABULATE-order-with-format-using-a-format-label/m-p/585897#M23241</link>
      <description>&lt;P&gt;I'm trying to run a tabulation where I run a bunch of single variable tables, with each variable having a custom format that is saved (notsorted) and defining the desired order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For categorical (discrete) variables this works well; using the solution in&amp;nbsp;&lt;A href="http://support.sas.com/kb/23/847.html" target="_blank"&gt;http://support.sas.com/kb/23/847.html&lt;/A&gt;&amp;nbsp;where we save the format with (notsorted) and use order=data on the tabulate (or on the class statement), everything is in order the way I want it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, for the continuous variables, we have a format that uses [best8.] as the default format, but with specific values cut out that I want to display at the bottom (imagine - values 6 and 9 have a special meaning and should go to the end).&amp;nbsp; This does not seem to work with the above solution - even if I treat it like a categorical in fact, if I use the [best8.] value anywhere in the format it fails to use the correct sorting and instead shows up as the dataset order (the normal meaning of order=data ignoring the format).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example.&amp;nbsp; It works fine with the 'y' variable, which is categorical, but with the 'x' continuous variable it will not sort properly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to make this work? Is this a bug, or expected functionality?&amp;nbsp; Maybe there's a better way for me to do the format that will work?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc format;
  value xf (notsorted)
   1-5=[best8.]
   7-8=[best8.]
   10=[best8.]
   9="Next to Bottom"
   6="Bottom"
 
   ;
  value yf   (notsorted)
  0 = "Top"
  1 = "Middle"
  2 = "Bottom"
  ;
  
  quit;
  
data test;  
  call streaminit(7);
  do x = 1 to 10;
    z = rand('uniform');
    y = mod(x,3);
    output;
  end;
  format x xf. y yf.;
run;

proc sort data=test;
  by z;
run;
 
%let var=x;
proc tabulate order=data;
  class &amp;amp;var./ preloadfmt;
  tables &amp;amp;var.,n;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Sep 2019 17:41:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-TABULATE-order-with-format-using-a-format-label/m-p/585897#M23241</guid>
      <dc:creator>snoopy369</dc:creator>
      <dc:date>2019-09-03T17:41:14Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TABULATE order with format using a [format.] label</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-TABULATE-order-with-format-using-a-format-label/m-p/585911#M23242</link>
      <description>What do you want to see for the 1 to 10 values in the table?</description>
      <pubDate>Tue, 03 Sep 2019 18:37:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-TABULATE-order-with-format-using-a-format-label/m-p/585911#M23242</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-09-03T18:37:32Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TABULATE order with format using a [format.] label</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-TABULATE-order-with-format-using-a-format-label/m-p/585913#M23243</link>
      <description>&lt;P&gt;I'm hoping to see:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;x:&lt;/P&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;P&gt;4&lt;/P&gt;
&lt;P&gt;5&lt;/P&gt;
&lt;P&gt;7&lt;/P&gt;
&lt;P&gt;8&lt;/P&gt;
&lt;P&gt;10&lt;/P&gt;
&lt;P&gt;Next to Bottom&lt;/P&gt;
&lt;P&gt;Bottom&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Sep 2019 18:41:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-TABULATE-order-with-format-using-a-format-label/m-p/585913#M23243</guid>
      <dc:creator>snoopy369</dc:creator>
      <dc:date>2019-09-03T18:41:01Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TABULATE order with format using a [format.] label</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-TABULATE-order-with-format-using-a-format-label/m-p/585926#M23244</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/46466"&gt;@snoopy369&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I'm trying to run a tabulation where I run a bunch of single variable tables, with each variable having a custom format that is saved (notsorted) and defining the desired order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For categorical (discrete) variables this works well; using the solution in&amp;nbsp;&lt;A href="http://support.sas.com/kb/23/847.html" target="_blank" rel="noopener"&gt;http://support.sas.com/kb/23/847.html&lt;/A&gt;&amp;nbsp;where we save the format with (notsorted) and use order=data on the tabulate (or on the class statement), everything is in order the way I want it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, for the continuous variables, we have a format that uses [best8.] as the default format, but with specific values cut out that I want to display at the bottom (imagine - values 6 and 9 have a special meaning and should go to the end).&amp;nbsp; This does not seem to work with the above solution - even if I treat it like a categorical in fact, if I use the [best8.] value anywhere in the format it fails to use the correct sorting and instead shows up as the dataset order (the normal meaning of order=data ignoring the format).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example.&amp;nbsp; It works fine with the 'y' variable, which is categorical, but with the 'x' continuous variable it will not sort properly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to make this work? Is this a bug, or expected functionality?&amp;nbsp; Maybe there's a better way for me to do the format that will work?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc format;
  value xf (notsorted)
   1-5=[best8.]
   7-8=[best8.]
   10=[best8.]
   9="Next to Bottom"
   6="Bottom"
 
   ;
  value yf   (notsorted)
  0 = "Top"
  1 = "Middle"
  2 = "Bottom"
  ;
  
  quit;
  
data test;  
  call streaminit(7);
  do x = 1 to 10;
    z = rand('uniform');
    y = mod(x,3);
    output;
  end;
  format x xf. y yf.;
run;

proc sort data=test;
  by z;
run;
 
%let var=x;
proc tabulate order=data;
  class &amp;amp;var./ preloadfmt;
  tables &amp;amp;var.,n;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PRELOADFMT does not work that way. If you checked the log you would see a message similar to:&lt;/P&gt;
&lt;PRE&gt;291
292  %let var=x;
293  proc tabulate data=work.test order=data;
294    class &amp;amp;var./ preloadfmt;
295    tables &amp;amp;var.,n;
296  run;

&lt;STRONG&gt;&lt;FONT color="#339966"&gt;WARNING: The format for variable x cannot be preloaded. A finite set of formatted values cannot
         be produced from the format.  The format is not recognized, is a SAS format, calls a
         function, or contains a nested format in its definition. Preload will have no effect.
&lt;/FONT&gt;&lt;/STRONG&gt;NOTE: There were 10 observations read from the data set WORK.TEST.
NOTE: PROCEDURE TABULATE used (Total process time):
      real time           0.09 seconds
      cpu time            0.03 seconds
&lt;/PRE&gt;
&lt;P&gt;You say that you want to see values like:&lt;/P&gt;
&lt;PRE&gt;I'm hoping to see:

1
2
3
4
5
7
8
10
Next to Bottom
Bottom
&lt;/PRE&gt;
&lt;P&gt;So you would have to create a format that creates a finite number of values.&lt;/P&gt;
&lt;P&gt;Like&lt;/P&gt;
&lt;PRE&gt;  value xf_alt (notsorted)
   1  ='1'  
   2  ='2'  
   3  ='3'  
   4  ='4'  
   5  ='5'  
   7  ='7'  
   8  ='8'  
   10 ='10' 
   9="Next to Bottom"
   6="Bottom"
 
   ;
&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Sep 2019 19:30:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-TABULATE-order-with-format-using-a-format-label/m-p/585926#M23244</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-09-03T19:30:35Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TABULATE order with format using a [format.] label</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-TABULATE-order-with-format-using-a-format-label/m-p/585930#M23245</link>
      <description>&lt;P&gt;That's certainly a good point. Was hoping there was a way around it; in this case there isn't really a way to make a discrete list (due to the continuous values being, well, continuous). Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 03 Sep 2019 19:44:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-TABULATE-order-with-format-using-a-format-label/m-p/585930#M23245</guid>
      <dc:creator>snoopy369</dc:creator>
      <dc:date>2019-09-03T19:44:15Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TABULATE order with format using a [format.] label</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-TABULATE-order-with-format-using-a-format-label/m-p/585961#M23246</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/46466"&gt;@snoopy369&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;That's certainly a good point. Was hoping there was a way around it; in this case there isn't really a way to make a discrete list (due to the continuous values being, well, continuous). Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You didn't really show "continuous" data. You showed discrete (integer)&amp;nbsp;examples. If your values actually are continuous but you want to show '1' when the range is 0 to 1 (or something else) you can use proc format to handle that: 0-1 = '1', or if a more traditional rounding was desired&amp;nbsp; 0.5 - 1.5 = '1'.&lt;/P&gt;
&lt;P&gt;The restriction is that the DISPLAY value has to be limited to discrete values, not ranges. Note that it can be a very large number of discrete values to work with PRELOADFMT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you think about for a moment it will make sense. Preloadfmt is to show a &lt;STRONG&gt;constant&lt;/STRONG&gt; list of results regardless of the input. So it will show a value even when no records have the value. But to have a fixed list of results you need to provide the fixed list. Another format such as BEST won't do that. It will display values up to 1.4E308 range.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Sep 2019 22:19:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-TABULATE-order-with-format-using-a-format-label/m-p/585961#M23246</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-09-03T22:19:57Z</dc:date>
    </item>
  </channel>
</rss>

