<?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 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-order-formatted/m-p/524559#M142647</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;When I run your code I get results&amp;nbsp; where the order of the categories is:&lt;/P&gt;
&lt;P&gt;Bordelrine&lt;/P&gt;
&lt;P&gt;Desirable&lt;/P&gt;
&lt;P&gt;High&lt;/P&gt;
&lt;P&gt;But I want to have same order of categories as in the proc format&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Desirable&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Bordelrine&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;High&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; proc format library=work;
value $Ffmt ( notsorted)
'Desirable'='Desirable'
'Borderline'='Borderline'
'High'='High';
Run;
    proc tabulate data=sashelp.heart ;
 class chol_status /preloadfmt  ;
 class status;
 format chol_status $ffmt.;
table Chol_Status,
      Status
    /printmiss;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 04 Jan 2019 14:43:40 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2019-01-04T14:43:40Z</dc:date>
    <item>
      <title>proc freq order=formatted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-order-formatted/m-p/524077#M142478</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I am working with proc freq.&lt;/P&gt;
&lt;P&gt;I want that in the output , the categories of &amp;nbsp;Cholesterol &amp;nbsp;status &amp;nbsp;will appear in same order as in proc format.&lt;/P&gt;
&lt;P&gt;Why the desired result is not coming please?&lt;/P&gt;
&lt;P&gt;MY code is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value $Ffmt ( notsorted)
'Desirable'='Desirable'
'Borderline'='Borderline'
'High'='High';
Run;

Data heart;
set sashelp.heart;
Format Chol_Status $Ffmt.;
Run;


proc freq data=heart order=formatted;
table Chol_Status*Status/chisq sparse outpct out=output1;
format Chol_Status $Fm2t.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Jan 2019 13:04:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-order-formatted/m-p/524077#M142478</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-01-02T13:04:41Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq order=formatted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-order-formatted/m-p/524089#M142482</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is what the proc freq documentation says about the order=FORMATTED option&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm#statug_freq_sect006.htm" target="_blank"&gt;https://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm#statug_freq_sect006.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;FORMATTED&lt;/P&gt;
&lt;P&gt;orders values by their formatted values (in ascending order). This order is dependent on the operating environment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the alphabetical order of formatted values will be used which is not what you want.&lt;/P&gt;
&lt;P&gt;What you want, as i understand it, is the order in which formatted values have been defined in the proc format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following program exports format definitions in a SAS dataset and uses this dataset to impose a custom&lt;/P&gt;
&lt;P&gt;sort order on the input dataset. Proc freq is then used with the order=data option (i used the program you gave in&lt;/P&gt;
&lt;P&gt;your other post on the same subject).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
    value $Fm1t ( notsorted)
    'Male'='M'
    'Female'='F';

    value $Fm2t ( notsorted)
    'Desirable'='Desirable'
    'Borderline'='Borderline'
    'High'='High';

    value $Fm3t ( notsorted)
    'Underweight'='Underweight'
    'Normal'='Normal weight'
    'Overweight'='Overweight';

    value $Fm4t ( notsorted)
    'Non-smoker'='Non-smoker'
    'Light (1-5)'='Light Smoker (1-5)'
    'Moderate (6-15)'='Moderate Smoker(6-15)'
    'Heavy (16-25)'='Heavy Smoker(16-25)'
    'Very Heavy (&amp;gt; 25)'='Very Heavy Smoker(&amp;gt; 25)';

    value $Fm5t ( notsorted)
    'Optimal'='Optimal Blood Pressure'
    'Normal'='Normal Blood Pressure'
    'High'='High Blood Pressure';

    select $Fm1t $Fm2t $Fm3t $Fm4t $Fm5t;
Run;

Data heart;
    set sashelp.heart;
    Format sex $Fm1t.
    Chol_Status $Fm2t.
    Weight_Status $Fm3t.
    Smoking_Status $Fm4t.
    BP_Status $Fm5t.;
Run;

%macro mmacro1(pred,i);

    proc format library=work.formats fmtlib out=desc;
        select $Fm&amp;amp;i.t;
    run;

    data sort_ds;
        set desc;
        value=start;
        n=_N_;
        keep value n;
    run;

    proc sql;
        CREATE TABLE heart_s AS
        SELECT a.*
        FROM heart a
        LEFT JOIN sort_ds b
        ON b.value=a.&amp;amp;pred.
        ORDER BY b.n;
    quit;

    proc freq data=heart_s order=data;  
        tables &amp;amp;pred*Status/chisq sparse outpct out=outfreq&amp;amp;i ;
        output out=stats&amp;amp;i chisq;
        format &amp;amp;pred $Fm&amp;amp;i.t.;
    run;

%mend;

%mmacro1(sex,1);
%mmacro1(Chol_Status,2);
%mmacro1(Weight_Status,3);
%mmacro1(Smoking_Status,4);
%mmacro1(BP_Status,5);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Jan 2019 14:18:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-order-formatted/m-p/524089#M142482</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-01-02T14:18:10Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq order=formatted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-order-formatted/m-p/524109#M142490</link>
      <description>&lt;P&gt;If you can tolerate a small change to the output, the simplest change would be to fool the software by inserting an extra blank.&amp;nbsp; Where you now have this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;format&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;value&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt;Ffmt &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt; notsorted&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="token string"&gt;'Desirable'&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'Desirable'&lt;/SPAN&gt;
&lt;SPAN class="token string"&gt;'Borderline'&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'Borderline'&lt;/SPAN&gt;
&lt;SPAN class="token string"&gt;'High'&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'High'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;Run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Change it to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;format&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;value&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt;Ffmt 
&lt;SPAN class="token string"&gt;'Desirable'&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;' Desirable'&lt;/SPAN&gt;
&lt;SPAN class="token string"&gt;'Borderline'&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'Borderline'&lt;/SPAN&gt;
&lt;SPAN class="token string"&gt;'High'&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'High'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;Run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The rest of the program requires no changes, if the extra blank is acceptable.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Jan 2019 15:07:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-order-formatted/m-p/524109#M142490</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-01-02T15:07:03Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq order=formatted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-order-formatted/m-p/524329#M142581</link>
      <description>&lt;P&gt;Another option to accomplish what you are asking may be to use a procedure that uses more of the formats information such as Proc Tabulate with the PRELOADFMT option. Maybe.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc format library=work;
value $Ffmt ( notsorted)
'Desirable'='Desirable'
'Borderline'='Borderline'
'High'='High';
Run;


proc tabulate data=sashelp.heart ;
 class chol_status /preloadfmt  ;
 class status;
 format chol_status $ffmt.;
table Chol_Status,
      Status
    /printmiss;
run;&lt;/PRE&gt;
&lt;P&gt;However not many procedures use Preloadfmt: Tabulate, Means/Summary and Report. So you may have to create statistics using other procedures such as Freq and then use one of Tabulate or Report to display them in order. Note that Tabulate requires additional options, such as the PRINTMISS above to display the values in the format order and use of other ORDER options may interfere with the order you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jan 2019 17:46:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-order-formatted/m-p/524329#M142581</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-01-03T17:46:48Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq order=formatted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-order-formatted/m-p/524559#M142647</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;When I run your code I get results&amp;nbsp; where the order of the categories is:&lt;/P&gt;
&lt;P&gt;Bordelrine&lt;/P&gt;
&lt;P&gt;Desirable&lt;/P&gt;
&lt;P&gt;High&lt;/P&gt;
&lt;P&gt;But I want to have same order of categories as in the proc format&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Desirable&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Bordelrine&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;High&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; proc format library=work;
value $Ffmt ( notsorted)
'Desirable'='Desirable'
'Borderline'='Borderline'
'High'='High';
Run;
    proc tabulate data=sashelp.heart ;
 class chol_status /preloadfmt  ;
 class status;
 format chol_status $ffmt.;
table Chol_Status,
      Status
    /printmiss;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jan 2019 14:43:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-order-formatted/m-p/524559#M142647</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-01-04T14:43:40Z</dc:date>
    </item>
  </channel>
</rss>

