<?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 on chararter variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-on-chararter-variable/m-p/263114#M51485</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/72261"&gt;@archibald﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Wouldn't it be acceptable to write "other" in lower case? This should move&amp;nbsp;it to the end of the alphabetical list (provided that all country names start with capital letters).&lt;/P&gt;</description>
    <pubDate>Tue, 12 Apr 2016 08:43:57 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2016-04-12T08:43:57Z</dc:date>
    <item>
      <title>proc freq on chararter variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-on-chararter-variable/m-p/263074#M51477</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ran&amp;nbsp;a proc freq on a character variable &amp;nbsp;"country_name" and I got &amp;nbsp;frequencies &amp;nbsp;in alphabatical order.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would have been satisfy with this result, but I need to have&amp;nbsp;"other"&amp;nbsp;as the last category in my output.&lt;/P&gt;&lt;P&gt;Thank you,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an abbreviated &amp;nbsp;list&lt;BR /&gt;Afghanistan&lt;BR /&gt;Albania&lt;BR /&gt;Bahrain&lt;BR /&gt;Barbados&lt;BR /&gt;Belarus&lt;/P&gt;&lt;P&gt;Cambodia&lt;/P&gt;&lt;P&gt;Denmark&lt;BR /&gt;Dominican Republic&lt;BR /&gt;Ecuador&lt;BR /&gt;Egypt&lt;/P&gt;&lt;P&gt;Fiji&lt;BR /&gt;Finland&lt;/P&gt;&lt;P&gt;Oman&lt;/P&gt;&lt;P&gt;Other&amp;nbsp;&lt;/P&gt;&lt;P&gt;.....&lt;/P&gt;&lt;P&gt;Zambia&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2016 02:31:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-on-chararter-variable/m-p/263074#M51477</guid>
      <dc:creator>archibald</dc:creator>
      <dc:date>2016-04-12T02:31:01Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq on chararter variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-on-chararter-variable/m-p/263075#M51478</link>
      <description>&lt;P&gt;I would capture the output to a table, sort as desired and then print the results. I feel like there should be a shorter way, but can't think of it at the moment.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have;
table countries/out=country_freq;
run;

data country_freq;
set country_freq;
if country='Other' then order=9999999;
else order=_n_;
run;

proc sort data=country_freq;
by order;
run;

proc print data=country_freq;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Apr 2016 02:39:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-on-chararter-variable/m-p/263075#M51478</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-12T02:39:14Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq on chararter variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-on-chararter-variable/m-p/263076#M51479</link>
      <description>&lt;P&gt;Thank you for your quick reply &amp;nbsp;Reeza. &amp;nbsp;I&amp;nbsp;will give it a try.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2016 02:41:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-on-chararter-variable/m-p/263076#M51479</guid>
      <dc:creator>archibald</dc:creator>
      <dc:date>2016-04-12T02:41:02Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq on chararter variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-on-chararter-variable/m-p/263114#M51485</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/72261"&gt;@archibald﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Wouldn't it be acceptable to write "other" in lower case? This should move&amp;nbsp;it to the end of the alphabetical list (provided that all country names start with capital letters).&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2016 08:43:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-on-chararter-variable/m-p/263114#M51485</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-04-12T08:43:57Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq on chararter variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-on-chararter-variable/m-p/263136#M51488</link>
      <description>&lt;P&gt;I think, the cleanest way to control the order is to define a variable, say, COUNTRY which does not contain the country name, but a numeric or character &lt;EM&gt;code&lt;/EM&gt;. If this variable replaced COUNTRY_NAME, you would even save disk space, because the code could be very short (possibly only 1 byte, definitely not more than 3!). Make sure that the code for "Other" is sorted last.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you would define a format assigning country names (and "Other") to the codes and assign it to variable COUNTRY. By default, the internal values are used to sort PROC FREQ output. So, with&amp;nbsp;&lt;FONT face="courier new,courier"&gt;tables country;&lt;/FONT&gt;&amp;nbsp;you can get an output showing the country names, sorted by the code you defined, hence with "Other" sorted last.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2016 11:00:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-on-chararter-variable/m-p/263136#M51488</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-04-12T11:00:39Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq on chararter variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-on-chararter-variable/m-p/263147#M51490</link>
      <description>&lt;P&gt;If you want to stick to your existing character variable, you could apply the ORDER= option of the PROC FREQ statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;One option is to use ORDER=DATA in conjunction with a sorted input dataset where observations with COUNTRY_NAME='Other' are sorted last. Example:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create view temp as
select * from have
order by country_name='Other', country_name;
quit;

proc freq data=temp order=data;
tables country_name;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI&gt;
&lt;LI&gt;Another option is to define a format for COUNTRY_NAME which sorts "Other" last and then use ORDER=FORMATTED. Unfortunately, PROC FREQ does not support the PRELOADFMT&amp;nbsp;option that is available in PROC MEANS and PROC TABULATE. (With this you can specify the order of format categories in the PROC FORMAT statement.) So, to apply ORDER=FORMATTED, "Other" must be made the alphabetically last formatted value. Most easily, you could use the lower-case label "other". Otherwise, you could achieve the desired sort order by indenting all country names by a blank and "Other" by 'A0'x (non-breakable space). To avoid the indentation, you could try to prefix "Other" with an invisible character (with an ASCII code &amp;gt;90 [dec]), but this is platform and device dependent. On my Windows workstation the below&amp;nbsp;format works with &lt;U&gt;listing&lt;/U&gt; output (not HTML, ...):&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value $country
'Other'='81'x 'Other' '01'x
other=[$40.];
run;

proc freq data=have order=formatted;
format country_name $country.;
tables country_name;
run;&lt;/CODE&gt;&lt;/PRE&gt;
(The '01'x compensates the "outdentation" caused by the invisible '81'x character.) I would not recommend this for production purposes.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Tue, 12 Apr 2016 11:54:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-on-chararter-variable/m-p/263147#M51490</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-04-12T11:54:27Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq on chararter variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-on-chararter-variable/m-p/263740#M51631</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh﻿&lt;/a&gt;&amp;nbsp;the first option is perfect! thanks so much!&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2016 03:16:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-on-chararter-variable/m-p/263740#M51631</guid>
      <dc:creator>archibald</dc:creator>
      <dc:date>2016-04-14T03:16:59Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq on chararter variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-on-chararter-variable/m-p/263741#M51632</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt;&amp;nbsp;thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2016 03:17:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-on-chararter-variable/m-p/263741#M51632</guid>
      <dc:creator>archibald</dc:creator>
      <dc:date>2016-04-14T03:17:55Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq on chararter variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-on-chararter-variable/m-p/264056#M51744</link>
      <description>&lt;P&gt;As a matter fact, this is pretty straigthfoward and interesting way of solving the issue, thanks!&amp;nbsp;but the only problem is to format &amp;nbsp;"other' afterward&amp;nbsp;so that it is in capital letter.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Apr 2016 01:53:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-on-chararter-variable/m-p/264056#M51744</guid>
      <dc:creator>archibald</dc:creator>
      <dc:date>2016-04-15T01:53:00Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq on chararter variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-on-chararter-variable/m-p/264057#M51745</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh﻿&lt;/a&gt;,&amp;nbsp;As a matter fact, this is pretty straigthfoward and interesting way of solving the issue, thanks!&amp;nbsp;but the only problem is to format &amp;nbsp;"other' afterward&amp;nbsp;so that it is in capital letter.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Apr 2016 01:53:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-on-chararter-variable/m-p/264057#M51745</guid>
      <dc:creator>archibald</dc:creator>
      <dc:date>2016-04-15T01:53:26Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq on chararter variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-on-chararter-variable/m-p/264117#M51768</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/72261"&gt;@archibald&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;...&amp;nbsp;but the only problem is to format &amp;nbsp;"other' afterward&amp;nbsp;so that it is in capital letter.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;But this is an easy "problem":&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value $country (default=40)
'other'='Other';
run;

proc freq data=have;
format country_name $country.;
tables country_name;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(The option "default=40" specifies the length of the format. You could adapt the value 40 to the length of the longest country name.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Apr 2016 08:37:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-on-chararter-variable/m-p/264117#M51768</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-04-15T08:37:48Z</dc:date>
    </item>
  </channel>
</rss>

