<?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: Group numeric variables into categories? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Group-numeric-variables-into-categories/m-p/687837#M208862</link>
    <description>&lt;P&gt;It might help to actually go back to your&amp;nbsp; "raw" data, i.e. before you added the "tot_male" "tot_female" and such variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Numeric codes can be turned in "groups" very easily and no additional variables would need to be added.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example if your race code is such that 1 and 2 are White (possibly separate codes for male/female), 3 &amp;amp; 4 for Black and so a a format such as&lt;/P&gt;
&lt;PRE&gt;Proc format;
value racesex
1,2 = 'White'
3,4 = 'Black'
5,6 = 'American Indian'
7,8 = 'Asian/Pacific Islander'
;
value hisp
 1='Non-Hispanic'
 2='Hispanic'
;&lt;BR /&gt;run;
&lt;/PRE&gt;
&lt;P&gt;Can create groups.&lt;/P&gt;
&lt;P&gt;And then use a report procedure like Proc tabulate to get the counts.&lt;/P&gt;
&lt;PRE&gt;Proc tabulate data=yourrawpopestimateset;
   class racevar ethvar; /*&amp;lt;= these would be the names of a race variable coded as above for race and ethnicity*/
  class county; /* note that a format could be turning raw codes of county to
                       legible text as well*/
  format racevar race. ethvar hisp;
  var popest; /* a single variable that has the population estimate instead of all those extraneous variables*/
  table county *(all='Total Population' racevar='Race' ethvar='Ethnicity')
        popest='Population'*sum=' '*f=comma12.
  ;
run;&lt;/PRE&gt;
&lt;P&gt;The same Where statement could be used to filter data, maybe, depending on what else has been done to the raw data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Similar formats can be made to use singe age values to create groups such as 5-year or 10-year groups when using agegrp other than 0.&lt;/P&gt;</description>
    <pubDate>Wed, 30 Sep 2020 14:49:44 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-09-30T14:49:44Z</dc:date>
    <item>
      <title>Group numeric variables into categories?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-numeric-variables-into-categories/m-p/687805#M208852</link>
      <description>&lt;P class="lia-indent-padding-left-30px"&gt;*New dataset, limited to 2019 and "all age groups";&lt;BR /&gt;Data est.estimates19;&lt;BR /&gt;Set est.estimates&lt;BR /&gt;(drop=state county stname);&lt;BR /&gt;Where year=12 and AGEGRP=0;&lt;BR /&gt;&lt;BR /&gt;Total=sum(tot_male, tot_female);&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;*Total population;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;white=sum(wa_male, wa_female);&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *White;&lt;BR /&gt;black=sum(ba_male, ba_female);&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *Black;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;natam=sum(IA_MALE, IA_FEMALE);&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;*Native American/Alaskan Native;&lt;BR /&gt;asian=sum(AA_MALE, AA_FEMALE);&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;*Asian;&lt;BR /&gt;island=sum(NA_MALE, NA_FEMALE);&amp;nbsp; &amp;nbsp; &amp;nbsp;*Native Hawaiian/Pacific Islander;&lt;BR /&gt;multi=sum(TOM_MALE, TOM_FEMALE); *Multi/other;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;hispanic=sum(H_male, H_female);&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;*Hispanic Ethnicity = 391,382;&lt;BR /&gt;Non_hispanic=sum(NH_MALE, NH_FEMALE); *Non-Hispanic Ethnicity = 6,437,792;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm getting population estimates for county from a US Census datasets; I've had to sum the data together (male+female) to get totals for race/ethnicity.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I need to &lt;U&gt;group these individual summed variables&lt;/U&gt; to get something that looks like this (numbers just for example):&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Ultimately, my goal is to be able to output this an Excel file and be able to filter by Category (race/ethnicity) or by CAT_detail as needed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;County&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;Category&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;CAT_Detail&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;Population&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Sunnyville&lt;/TD&gt;&lt;TD&gt;Race&lt;/TD&gt;&lt;TD&gt;White&lt;/TD&gt;&lt;TD&gt;5,602,223&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Sunnyville&lt;/TD&gt;&lt;TD&gt;Ethnicity&lt;/TD&gt;&lt;TD&gt;Non-Hispanic&lt;/TD&gt;&lt;TD&gt;7,56,010&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Sunnyville&lt;/TD&gt;&lt;TD&gt;Race&lt;/TD&gt;&lt;TD&gt;Black&lt;/TD&gt;&lt;TD&gt;1,501,011&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Sunnyville&lt;/TD&gt;&lt;TD&gt;Race&lt;/TD&gt;&lt;TD&gt;Native American/Alaskan Native&lt;/TD&gt;&lt;TD&gt;21,011&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Sunnyville&lt;/TD&gt;&lt;TD&gt;Ethnicty&lt;/TD&gt;&lt;TD&gt;Hispanic&lt;/TD&gt;&lt;TD&gt;1,002,001&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Wed, 30 Sep 2020 13:25:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-numeric-variables-into-categories/m-p/687805#M208852</guid>
      <dc:creator>SAS93</dc:creator>
      <dc:date>2020-09-30T13:25:02Z</dc:date>
    </item>
    <item>
      <title>Re: Group numeric variables into categories?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-numeric-variables-into-categories/m-p/687808#M208853</link>
      <description>&lt;P&gt;Proc sql;&lt;/P&gt;&lt;P&gt;create table want as&lt;/P&gt;&lt;P&gt;select a.country, a.category, a.cat_detail, sum (desired_avariable) as Poutaion_sum&lt;/P&gt;&lt;P&gt;from have as a&lt;/P&gt;&lt;P&gt;group by&amp;nbsp;a.country, a.category, a.cat_detail;&lt;/P&gt;&lt;P&gt;quit;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 13:29:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-numeric-variables-into-categories/m-p/687808#M208853</guid>
      <dc:creator>ghazanfar_a</dc:creator>
      <dc:date>2020-09-30T13:29:24Z</dc:date>
    </item>
    <item>
      <title>Re: Group numeric variables into categories?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-numeric-variables-into-categories/m-p/687837#M208862</link>
      <description>&lt;P&gt;It might help to actually go back to your&amp;nbsp; "raw" data, i.e. before you added the "tot_male" "tot_female" and such variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Numeric codes can be turned in "groups" very easily and no additional variables would need to be added.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example if your race code is such that 1 and 2 are White (possibly separate codes for male/female), 3 &amp;amp; 4 for Black and so a a format such as&lt;/P&gt;
&lt;PRE&gt;Proc format;
value racesex
1,2 = 'White'
3,4 = 'Black'
5,6 = 'American Indian'
7,8 = 'Asian/Pacific Islander'
;
value hisp
 1='Non-Hispanic'
 2='Hispanic'
;&lt;BR /&gt;run;
&lt;/PRE&gt;
&lt;P&gt;Can create groups.&lt;/P&gt;
&lt;P&gt;And then use a report procedure like Proc tabulate to get the counts.&lt;/P&gt;
&lt;PRE&gt;Proc tabulate data=yourrawpopestimateset;
   class racevar ethvar; /*&amp;lt;= these would be the names of a race variable coded as above for race and ethnicity*/
  class county; /* note that a format could be turning raw codes of county to
                       legible text as well*/
  format racevar race. ethvar hisp;
  var popest; /* a single variable that has the population estimate instead of all those extraneous variables*/
  table county *(all='Total Population' racevar='Race' ethvar='Ethnicity')
        popest='Population'*sum=' '*f=comma12.
  ;
run;&lt;/PRE&gt;
&lt;P&gt;The same Where statement could be used to filter data, maybe, depending on what else has been done to the raw data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Similar formats can be made to use singe age values to create groups such as 5-year or 10-year groups when using agegrp other than 0.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 14:49:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-numeric-variables-into-categories/m-p/687837#M208862</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-09-30T14:49:44Z</dc:date>
    </item>
    <item>
      <title>Re: Group numeric variables into categories?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-numeric-variables-into-categories/m-p/687857#M208868</link>
      <description>The variables like tot_male and ba_female are numeric variables. They provide the count of the population in a given county.&lt;BR /&gt;</description>
      <pubDate>Wed, 30 Sep 2020 15:27:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-numeric-variables-into-categories/m-p/687857#M208868</guid>
      <dc:creator>SAS93</dc:creator>
      <dc:date>2020-09-30T15:27:29Z</dc:date>
    </item>
    <item>
      <title>Re: Group numeric variables into categories?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-numeric-variables-into-categories/m-p/687870#M208869</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/297876"&gt;@SAS93&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;The variables like tot_male and ba_female are numeric variables. They provide the count of the population in a given county.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Doesn't invalidate what I posted.&lt;/P&gt;
&lt;P&gt;I suspect you are using one of the US Census single-age by race and county data sets. The code I posted is intended to work pretty much with an "as read" version of the data where no one has mucked about creating superfluous race male/female variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that is the file you are using I have been using them since 2007. And create race/ age/ ethicity /county (and multi county regions of my state) just by using formats applied to the variables. (And always thought including summaries like the agegroup=0 to be poor design)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Proc tabulate keyword ALL would sum all of the race values to get that overall.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 15:49:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-numeric-variables-into-categories/m-p/687870#M208869</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-09-30T15:49:17Z</dc:date>
    </item>
  </channel>
</rss>

