<?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: Using proc format to order table variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-proc-format-to-order-table-variables/m-p/951034#M371823</link>
    <description>&lt;P&gt;It's sorting based on the format, as you specified - Yes sorts after No alphabetically.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 18 Nov 2024 00:50:26 GMT</pubDate>
    <dc:creator>quickbluefish</dc:creator>
    <dc:date>2024-11-18T00:50:26Z</dc:date>
    <item>
      <title>Using proc format to order table variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-proc-format-to-order-table-variables/m-p/951032#M371822</link>
      <description>&lt;P&gt;Hi, I've been trying to get this 2x2 table (generated through proc freq) sorted so it shows 1 in the first column + row, and 0 in the second column + row. Even specifying "order=formatted", it still displays 0 in the first column + row which messes up some of the calculated stats. Any ideas what is going wrong here? Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc format;&lt;BR /&gt;value noyes 1="Yes" 0="No" ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc freq data=mydata.study order=formatted;&lt;BR /&gt;ods exclude riskdiffcol2;&lt;BR /&gt;tables ins*m1/nocol nopercent nocum riskdiff chisq;&lt;BR /&gt;format ins m1 noyes.;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2024 00:24:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-proc-format-to-order-table-variables/m-p/951032#M371822</guid>
      <dc:creator>myaarylon</dc:creator>
      <dc:date>2024-11-18T00:24:51Z</dc:date>
    </item>
    <item>
      <title>Re: Using proc format to order table variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-proc-format-to-order-table-variables/m-p/951034#M371823</link>
      <description>&lt;P&gt;It's sorting based on the format, as you specified - Yes sorts after No alphabetically.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2024 00:50:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-proc-format-to-order-table-variables/m-p/951034#M371823</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2024-11-18T00:50:26Z</dc:date>
    </item>
    <item>
      <title>Re: Using proc format to order table variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-proc-format-to-order-table-variables/m-p/951035#M371824</link>
      <description>&lt;P&gt;Can you clarify why it matters what order the values appear in the table?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the goal is just to print a 2x2 table why not use PROC FREQ to get the counts and then use PROC PRINT or PROC REPORT to make the printout?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could convert your boolean 0=No 1=Yes values into 1=Yes 2=No values instead by subtracting from 2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input a b count;
  x=2-a;
  y=2-b;
cards;
1 1 1
1 0 2
0 1 3
0 0 4
;

proc format ;
  value yn 0='No' 1='Yes';
  value ny 2='No' 1='Yes';
run;

proc freq data=have ;
  ods exclude riskdiffcol2;
  tables a*b/nocol nopercent nocum riskdiff chisq;
  weight count;
  format a b yn.;
run;

proc freq data=have ;
  ods exclude riskdiffcol2;
  tables x*y/nocol nopercent nocum riskdiff chisq;
  weight count;
  format x y ny.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Same counts, same labels, reversed order.&lt;/P&gt;
&lt;PRE&gt;Table of a by b

a         b

Frequency|
Row Pct  |No      |Yes     |  Total
---------+--------+--------+
No       |      4 |      3 |      7
         |  57.14 |  42.86 |
---------+--------+--------+
Yes      |      2 |      1 |      3
         |  66.67 |  33.33 |
---------+--------+--------+
Total           6        4       10


Table of x by y

x         y

Frequency|
Row Pct  |Yes     |No      |  Total
---------+--------+--------+
Yes      |      1 |      2 |      3
         |  33.33 |  66.67 |
---------+--------+--------+
No       |      3 |      4 |      7
         |  42.86 |  57.14 |
---------+--------+--------+
Total           4        6       10
&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Nov 2024 00:51:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-proc-format-to-order-table-variables/m-p/951035#M371824</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-11-18T00:51:24Z</dc:date>
    </item>
    <item>
      <title>Re: Using proc format to order table variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-proc-format-to-order-table-variables/m-p/951038#M371825</link>
      <description>&lt;P&gt;With order=formatted SAS will print the results based on sort order of the formatted values - &lt;STRONG&gt;N&lt;/STRONG&gt;o sorts before &lt;STRONG&gt;Y&lt;/STRONG&gt;es.&lt;/P&gt;
&lt;P&gt;You could use a lowercase &lt;STRONG&gt;n&lt;/STRONG&gt; for &lt;STRONG&gt;n&lt;/STRONG&gt;o&amp;nbsp;or add a leading blank to Yes to get the desired order in your report.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname mydata "%sysfunc(pathname(work))";

data mydata.study;
  do ins=0 to 1;
    do m1=0 to 1;
      output;
    end;
  end;
run;

proc format;
  value noyes 1=" Yes" 0="No";
run;

proc freq data=mydata.study order=formatted;
  ods exclude riskdiffcol2;
  tables ins*m1/nocol nopercent nocum riskdiff chisq;
  format ins m1 noyes.;
run;&lt;/CODE&gt;&lt;/PRE&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="Patrick_0-1731891509499.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/102295i9FB4CE991D466DDC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1731891509499.png" alt="Patrick_0-1731891509499.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2024 01:00:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-proc-format-to-order-table-variables/m-p/951038#M371825</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-11-18T01:00:19Z</dc:date>
    </item>
    <item>
      <title>Re: Using proc format to order table variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-proc-format-to-order-table-variables/m-p/951040#M371826</link>
      <description>&lt;P&gt;By the way, if you're looking for the typical E+/E-, D+/D-&amp;nbsp; (exposure status, disease status) as is common in epidemiology -- you can do that with these formats (and using order=formatted as you were).&amp;nbsp; Keeping things as 0/1 is much more handy for other calculations.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value fexp
    0='E-'
    1='E+'
    ;
value fdis
    0='D-'
    1='D+'
    ;
run;

proc freq data=test order=formatted;
format exp fexp. dis fdis.;
table exp*dis / missing norow nocol nopercent nocum chisq;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Nov 2024 01:05:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-proc-format-to-order-table-variables/m-p/951040#M371826</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2024-11-18T01:05:56Z</dc:date>
    </item>
    <item>
      <title>Re: Using proc format to order table variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-proc-format-to-order-table-variables/m-p/951042#M371827</link>
      <description>&lt;P&gt;Patrick already gave you the right solution.&lt;/P&gt;
&lt;P&gt;Here is alternative way by using PROC SORT + ORDER=DATA .But you need make sure there are always have 0 and 1 in each row and column variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data study;
  do ins=0 to 1;
    do m1=0 to 1;
      output;
    end;
  end;
run;

proc format;
  value noyes 1="Yes" 0="No";
run;
proc sort data=study;by descending ins descending m1 ;run;
proc freq data=study order=data;
  ods exclude riskdiffcol2;
  tables ins*m1/nocol nopercent nocum riskdiff chisq;
  format ins m1 noyes.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Nov 2024 01:32:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-proc-format-to-order-table-variables/m-p/951042#M371827</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-11-18T01:32:49Z</dc:date>
    </item>
    <item>
      <title>Re: Using proc format to order table variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-proc-format-to-order-table-variables/m-p/951147#M371858</link>
      <description>This worked, thank you!!</description>
      <pubDate>Mon, 18 Nov 2024 21:48:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-proc-format-to-order-table-variables/m-p/951147#M371858</guid>
      <dc:creator>myaarylon</dc:creator>
      <dc:date>2024-11-18T21:48:13Z</dc:date>
    </item>
    <item>
      <title>Re: Using proc format to order table variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-proc-format-to-order-table-variables/m-p/951148#M371859</link>
      <description>I needed them in a certain order to calculate the correct riskdiff! thanks</description>
      <pubDate>Mon, 18 Nov 2024 21:51:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-proc-format-to-order-table-variables/m-p/951148#M371859</guid>
      <dc:creator>myaarylon</dc:creator>
      <dc:date>2024-11-18T21:51:40Z</dc:date>
    </item>
  </channel>
</rss>

