<?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 Categorising income groups in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Categorising-income-groups/m-p/43753#M11464</link>
    <description>Hi Colleagues,&lt;BR /&gt;
&lt;BR /&gt;
I need to categorise personal incomes (PPI1) into 13 categories and all others as “.”.&lt;BR /&gt;
&lt;BR /&gt;
I have attempted with the following codes but it produced strange categorisations.&lt;BR /&gt;
&lt;BR /&gt;
Could anyone help me?&lt;BR /&gt;
&lt;BR /&gt;
data data_families3;&lt;BR /&gt;
set data_families2;&lt;BR /&gt;
IF PPI1 &amp;lt; 10000 THEN PPI2 = 01;&lt;BR /&gt;
ELSE IF PPI1 = 10000 and PPI1 &amp;lt; 15000 THEN PPI2 = 02;&lt;BR /&gt;
ELSE IF PPI1 = 15000 and PPI1 &amp;lt; 20000 THEN PPI2 = 03;&lt;BR /&gt;
ELSE IF PPI1 = 20000 and PPI1 &amp;lt; 25000 THEN PPI2 = 04;&lt;BR /&gt;
ELSE IF PPI1 = 25000 and PPI1 &amp;lt; 30000 THEN PPI2 = 05;&lt;BR /&gt;
ELSE IF PPI1 = 30000 and PPI1 &amp;lt; 40000 THEN PPI2 = 06;&lt;BR /&gt;
ELSE IF PPI1 = 40000 and PPI1 &amp;lt; 50000 THEN PPI2 = 07;&lt;BR /&gt;
ELSE IF PPI1 = 50000 and PPI1 &amp;lt; 60000 THEN PPI2 = 08;&lt;BR /&gt;
ELSE IF PPI1 = 60000 and PPI1 &amp;lt; 70000 THEN PPI2 = 09;&lt;BR /&gt;
ELSE IF PPI1 = 70000 and PPI1 &amp;lt; 80000 THEN PPI2 = 10;&lt;BR /&gt;
ELSE IF PPI1 = 80000 and PPI1 &amp;lt; 90000 THEN PPI2 = 11;&lt;BR /&gt;
ELSE IF PPI1 = 9000 and PPI1 &amp;lt; 100000 THEN PPI2 = 12;&lt;BR /&gt;
ELSE IF PPI1 &amp;gt;= 100000 then PPI2=13;&lt;BR /&gt;
ELSE PPI2 = .;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Thanks &lt;BR /&gt;
&lt;BR /&gt;
Mirisage</description>
    <pubDate>Fri, 02 Jul 2010 16:20:00 GMT</pubDate>
    <dc:creator>Mirisage</dc:creator>
    <dc:date>2010-07-02T16:20:00Z</dc:date>
    <item>
      <title>Categorising income groups</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Categorising-income-groups/m-p/43753#M11464</link>
      <description>Hi Colleagues,&lt;BR /&gt;
&lt;BR /&gt;
I need to categorise personal incomes (PPI1) into 13 categories and all others as “.”.&lt;BR /&gt;
&lt;BR /&gt;
I have attempted with the following codes but it produced strange categorisations.&lt;BR /&gt;
&lt;BR /&gt;
Could anyone help me?&lt;BR /&gt;
&lt;BR /&gt;
data data_families3;&lt;BR /&gt;
set data_families2;&lt;BR /&gt;
IF PPI1 &amp;lt; 10000 THEN PPI2 = 01;&lt;BR /&gt;
ELSE IF PPI1 = 10000 and PPI1 &amp;lt; 15000 THEN PPI2 = 02;&lt;BR /&gt;
ELSE IF PPI1 = 15000 and PPI1 &amp;lt; 20000 THEN PPI2 = 03;&lt;BR /&gt;
ELSE IF PPI1 = 20000 and PPI1 &amp;lt; 25000 THEN PPI2 = 04;&lt;BR /&gt;
ELSE IF PPI1 = 25000 and PPI1 &amp;lt; 30000 THEN PPI2 = 05;&lt;BR /&gt;
ELSE IF PPI1 = 30000 and PPI1 &amp;lt; 40000 THEN PPI2 = 06;&lt;BR /&gt;
ELSE IF PPI1 = 40000 and PPI1 &amp;lt; 50000 THEN PPI2 = 07;&lt;BR /&gt;
ELSE IF PPI1 = 50000 and PPI1 &amp;lt; 60000 THEN PPI2 = 08;&lt;BR /&gt;
ELSE IF PPI1 = 60000 and PPI1 &amp;lt; 70000 THEN PPI2 = 09;&lt;BR /&gt;
ELSE IF PPI1 = 70000 and PPI1 &amp;lt; 80000 THEN PPI2 = 10;&lt;BR /&gt;
ELSE IF PPI1 = 80000 and PPI1 &amp;lt; 90000 THEN PPI2 = 11;&lt;BR /&gt;
ELSE IF PPI1 = 9000 and PPI1 &amp;lt; 100000 THEN PPI2 = 12;&lt;BR /&gt;
ELSE IF PPI1 &amp;gt;= 100000 then PPI2=13;&lt;BR /&gt;
ELSE PPI2 = .;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Thanks &lt;BR /&gt;
&lt;BR /&gt;
Mirisage</description>
      <pubDate>Fri, 02 Jul 2010 16:20:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Categorising-income-groups/m-p/43753#M11464</guid>
      <dc:creator>Mirisage</dc:creator>
      <dc:date>2010-07-02T16:20:00Z</dc:date>
    </item>
    <item>
      <title>Re: Categorising income groups</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Categorising-income-groups/m-p/43754#M11465</link>
      <description>A couple of things.&lt;BR /&gt;
&lt;BR /&gt;
The first "=" in the first 11 ELSE statements needs to be "&amp;gt;=".  SAS also allows syntax like&lt;BR /&gt;
ELSE IF 10000 LE pp1 LT 15000 THEN ppi1 = 02;&lt;BR /&gt;
&lt;BR /&gt;
The&lt;BR /&gt;
IF PPI1 LT 10000 THEN PPI2 = 01;&lt;BR /&gt;
should be&lt;BR /&gt;
IF . LT PPI1 LT 10000 THEN PPI2 = 01; &lt;BR /&gt;
Your statement assigns 01 to missing values for PP1.&lt;BR /&gt;
&lt;BR /&gt;
Doc Muhlbaier&lt;BR /&gt;
Duke</description>
      <pubDate>Fri, 02 Jul 2010 17:40:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Categorising-income-groups/m-p/43754#M11465</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2010-07-02T17:40:21Z</dc:date>
    </item>
    <item>
      <title>Re: Categorising income groups</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Categorising-income-groups/m-p/43755#M11466</link>
      <description>Hi:&lt;BR /&gt;
  I wonder whether this 9000 instead of 90000 is one possible cause??&lt;BR /&gt;
[pre]&lt;BR /&gt;
ELSE IF PPI1 = 9000 and PPI1 &amp;lt; 100000 THEN PPI2 = 12;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
My tendency would be to do the assignment of a value with a user-defined format and a INPUT/PUT statement. What you really have is a mini-table of values which should be used to create PPI2. A user-defined format can do this quite well. The key is understanding that the INPUT function takes a character variable and creates a numeric variable. That means the PUT function is used with PPI1 to create a character variable from the MKPPI user-defined format...essentially bypassing the need for a set of nested IF/ELSE statements by using the format to do the lookup. The syntax &lt;B&gt;&lt;BR /&gt;
10000-&amp;lt;15000 = '2' &lt;/B&gt; in the user-defined format defines a range of values from 10000 to slighly less than 15000 as being value '2'.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
** See results below;&lt;BR /&gt;
proc format;&lt;BR /&gt;
  value mkppi &lt;BR /&gt;
           low-&amp;lt;10000 = '1'&lt;BR /&gt;
          10000-&amp;lt;15000 = '2'&lt;BR /&gt;
          15000-&amp;lt;20000 = '3'&lt;BR /&gt;
          20000-&amp;lt;25000 = '4' &lt;BR /&gt;
          25000-&amp;lt;30000  = '5' &lt;BR /&gt;
          30000-&amp;lt;40000  = '6' &lt;BR /&gt;
          40000-&amp;lt;50000  = '7' &lt;BR /&gt;
          50000-&amp;lt;60000  = '8' &lt;BR /&gt;
          60000-&amp;lt;70000  = '9' &lt;BR /&gt;
          70000-&amp;lt;80000  = '10' &lt;BR /&gt;
          80000-&amp;lt;90000  = '11' &lt;BR /&gt;
          90000-&amp;lt;100000  = '12' &lt;BR /&gt;
         100000-high ='13' &lt;BR /&gt;
         other = .;&lt;BR /&gt;
run;&lt;BR /&gt;
                         &lt;BR /&gt;
data testfmt;&lt;BR /&gt;
  infile datalines;&lt;BR /&gt;
  input name $ ppi1;&lt;BR /&gt;
  ppi2 = input(put(ppi1,mkppi.),2.);&lt;BR /&gt;
  put _all_;&lt;BR /&gt;
  format ppi2 z2.;&lt;BR /&gt;
return;&lt;BR /&gt;
datalines;&lt;BR /&gt;
alan     99&lt;BR /&gt;
bob  150000&lt;BR /&gt;
carl  15000&lt;BR /&gt;
dana  14999&lt;BR /&gt;
eliza 59999&lt;BR /&gt;
fred  60001&lt;BR /&gt;
george .&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
  &lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
The LOG results show:&lt;BR /&gt;
[pre]&lt;BR /&gt;
2186&lt;BR /&gt;
2187  data testfmt;&lt;BR /&gt;
2188    infile datalines;&lt;BR /&gt;
2189    input name $ ppi1;&lt;BR /&gt;
2190    ppi2 = input(put(ppi1,mkppi.),2.);&lt;BR /&gt;
2191    put _all_;&lt;BR /&gt;
2192    format ppi2 z2.;&lt;BR /&gt;
2193  return;&lt;BR /&gt;
2194  datalines;&lt;BR /&gt;
                                            &lt;BR /&gt;
name=alan ppi1=99 ppi2=01 _ERROR_=0 _N_=1&lt;BR /&gt;
name=bob ppi1=150000 ppi2=13 _ERROR_=0 _N_=2&lt;BR /&gt;
name=carl ppi1=15000 ppi2=03 _ERROR_=0 _N_=3&lt;BR /&gt;
name=dana ppi1=14999 ppi2=02 _ERROR_=0 _N_=4&lt;BR /&gt;
name=eliza ppi1=59999 ppi2=08 _ERROR_=0 _N_=5&lt;BR /&gt;
name=fred ppi1=60001 ppi2=09 _ERROR_=0 _N_=6&lt;BR /&gt;
name=george ppi1=. ppi2=. _ERROR_=0 _N_=7&lt;BR /&gt;
NOTE: The data set WORK.TESTFMT has 7 observations and 3 variables.&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.01 seconds&lt;BR /&gt;
      cpu time            0.00 seconds&lt;BR /&gt;
&lt;BR /&gt;
[/pre]</description>
      <pubDate>Fri, 02 Jul 2010 17:47:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Categorising-income-groups/m-p/43755#M11466</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-07-02T17:47:10Z</dc:date>
    </item>
    <item>
      <title>Re: Categorising income groups</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Categorising-income-groups/m-p/43756#M11467</link>
      <description>Hi Doc Muhlbaier Duke ,&lt;BR /&gt;
&lt;BR /&gt;
This is great!&lt;BR /&gt;
&lt;BR /&gt;
It worked very well.&lt;BR /&gt;
&lt;BR /&gt;
Many thanks,&lt;BR /&gt;
Mirisage</description>
      <pubDate>Tue, 06 Jul 2010 14:46:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Categorising-income-groups/m-p/43756#M11467</guid>
      <dc:creator>Mirisage</dc:creator>
      <dc:date>2010-07-06T14:46:48Z</dc:date>
    </item>
  </channel>
</rss>

