<?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 table order options in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-table-order-options/m-p/607450#M176607</link>
    <description>&lt;P&gt;Thank you so much for the suggestion!&amp;nbsp; A co-worker suggested I look at formats, too.&amp;nbsp; I'm guessing this means there is no simple way to do it without proc format then?&amp;nbsp; Thank you!&lt;/P&gt;</description>
    <pubDate>Tue, 26 Nov 2019 17:53:19 GMT</pubDate>
    <dc:creator>thackkr</dc:creator>
    <dc:date>2019-11-26T17:53:19Z</dc:date>
    <item>
      <title>proc freq table order options</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-table-order-options/m-p/607438#M176599</link>
      <description>&lt;P&gt;VERY new SAS user here &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp; I'm looking for a way to tell SAS to display table values in the order in which I hard coded them.&amp;nbsp; For example, I&amp;nbsp;created a subset of&amp;nbsp;an existing data set and recoded education level categorical data like this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; _EDUCAG = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; educat = &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New"&gt;"No HS Diploma"&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; _EDUCAG = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; educat = &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New"&gt;"HS Diploma"&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; _EDUCAG = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; educat = &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New"&gt;"Some College"&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; _EDUCAG = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New"&gt;4&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; educat = &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New"&gt;"College Grad"&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; _EDUCAG = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New"&gt;9&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; educat = &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New"&gt;"Don't Know"&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I use proc freq to create frequency and crosstabulation tables, I'd like to know if there is a way to include an ORDER= statement that will display the table data in the order in which I created it (e.g., List "No HS Diploma" first, "HS Diploma" next, etc.). It looks like the default is to list the categories alphabetically.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 17:17:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-table-order-options/m-p/607438#M176599</guid>
      <dc:creator>thackkr</dc:creator>
      <dc:date>2019-11-26T17:17:41Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq table order options</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-table-order-options/m-p/607440#M176601</link>
      <description>&lt;P&gt;Try Formats :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
	value educat 1="No HS Diploma"
				2="HS Diploma"
				3="Some College"
				4="College Grad"
				9="Don't Know";
run;


data have;
	do _EDUCAG =1,2,3,4,9;
		output;
	end;
run;


proc freq data=have;
	tables _EDUCAG / missing;

	format _EDUCAG educat.;
run; 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Nov 2019 17:25:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-table-order-options/m-p/607440#M176601</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2019-11-26T17:25:02Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq table order options</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-table-order-options/m-p/607450#M176607</link>
      <description>&lt;P&gt;Thank you so much for the suggestion!&amp;nbsp; A co-worker suggested I look at formats, too.&amp;nbsp; I'm guessing this means there is no simple way to do it without proc format then?&amp;nbsp; Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 17:53:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-table-order-options/m-p/607450#M176607</guid>
      <dc:creator>thackkr</dc:creator>
      <dc:date>2019-11-26T17:53:19Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq table order options</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-table-order-options/m-p/607467#M176611</link>
      <description>&lt;P&gt;What about this? When hard-coding, you may want to consider index.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc freq data=sashelp.cars;
	where make in ("Acura" "Audi" "BMW");
	tables make;run; 

	data temp; set sashelp.cars;
		if make= "BMW" then NewMake= "1. BMW";
		if make= "Audi" then NewMake= "2. Audi";
		if make= "Acura" then NewMake= "3. Third";
		run;
proc freq data= temp;
	tables NewMake ;run; 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Nov 2019 19:01:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-table-order-options/m-p/607467#M176611</guid>
      <dc:creator>braam</dc:creator>
      <dc:date>2019-11-26T19:01:46Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq table order options</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-table-order-options/m-p/607472#M176615</link>
      <description>&lt;P&gt;Hadn't thought of that!&amp;nbsp; Thanks so much for the suggestion &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 19:22:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-table-order-options/m-p/607472#M176615</guid>
      <dc:creator>thackkr</dc:creator>
      <dc:date>2019-11-26T19:22:28Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq table order options</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-table-order-options/m-p/607507#M176633</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/301315"&gt;@thackkr&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you so much for the suggestion!&amp;nbsp; A co-worker suggested I look at formats, too.&amp;nbsp; I'm guessing this means there is no simple way to do it without proc format then?&amp;nbsp; Thank you!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Sort and use ORDER=Data option:&lt;/P&gt;
&lt;PRE&gt;data example;
   do i= 1 to 100;
      _educag = rand('integer',1,5);
      if _educag=5 then _educag=9;
      if _EDUCAG = 1 then educat = "No HS Diploma";
      if _EDUCAG = 2 then educat = "HS Diploma";
      if _EDUCAG = 3 then educat = "Some College";
      if _EDUCAG = 4 then educat = "College Grad";
      if _EDUCAG = 9 then educat = "Don't Know";
      output;
   end;
run;

proc sort data=example;
  by _educag;
run;

proc freq data=example order=data;
   tables educat;
run;
&lt;/PRE&gt;
&lt;P&gt;&lt;FONT size="5"&gt;&lt;STRONG&gt;However, &lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT size="3"&gt;if you want to summarize many variables at once it is very unlikely that a sort order would be correct for more than one variable.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="3"&gt;IMHO the Format approach is likely the most flexible in the long run. All you need to get a summary of No HS diploma, HS or college and Don't Know is a new format. No additional variables added Also the groups created by formats will generally be used by any analysis or graphing procedure.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 20:59:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-table-order-options/m-p/607507#M176633</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-11-26T20:59:21Z</dc:date>
    </item>
  </channel>
</rss>

