<?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: Groupings by Age in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Groupings-by-Age/m-p/715864#M27399</link>
    <description>&lt;P&gt;Also you say "group by three years" but 17 to 20 is 4: 17, 18, 19 and 20.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A common way to handle such groups in use a custom format and apply the format in the procedures that are used to count things.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
 input Age 	Users;
datalines;
17 	1
18 	2
19 	5
20 	3
21 	9
22 	9
23 	2
24 	5
25 	3
26 	2
;
proc format;
value myagegrp
17-20 = '17 to 20'
21-23 = '21 to 23'
24-26 = '24 to 26'
;
proc freq data=have;
   tables age;
   format age myagegrp.;
   weight users;
run;&lt;/PRE&gt;
&lt;P&gt;A very strong advantage of using this format approach is that you can create multiple formats that are used with the same data as needed.&lt;/P&gt;
&lt;P&gt;The groups created by proc format will be honored by report procedures like Report and Tabulate, and most graphing and analysis procedures.&lt;/P&gt;</description>
    <pubDate>Mon, 01 Feb 2021 18:51:57 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-02-01T18:51:57Z</dc:date>
    <item>
      <title>Groupings by Age</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Groupings-by-Age/m-p/715856#M27397</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to group by age and use the sums of the groups. For instance, if I am using this data table:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 96pt;" border="0" width="123px" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="61.3333px" height="15px" style="height: 15.0pt; width: 48pt;"&gt;Age&lt;/TD&gt;
&lt;TD width="66px" height="15px" style="width: 48pt;"&gt;Users&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="61.3333px" height="15px" align="right" style="height: 15.0pt;"&gt;17&lt;/TD&gt;
&lt;TD width="66px" height="15px" align="right"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="61.3333px" height="15px" align="right" style="height: 15.0pt;"&gt;18&lt;/TD&gt;
&lt;TD width="66px" height="15px" align="right"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="61.3333px" height="15px" align="right" style="height: 15.0pt;"&gt;19&lt;/TD&gt;
&lt;TD width="66px" height="15px" align="right"&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="61.3333px" height="15px" align="right" style="height: 15.0pt;"&gt;20&lt;/TD&gt;
&lt;TD width="66px" height="15px" align="right"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="61.3333px" height="15px" align="right" style="height: 15.0pt;"&gt;21&lt;/TD&gt;
&lt;TD width="66px" height="15px" align="right"&gt;9&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="61.3333px" height="15px" align="right" style="height: 15.0pt;"&gt;22&lt;/TD&gt;
&lt;TD width="66px" height="15px" align="right"&gt;9&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="61.3333px" height="15px" align="right" style="height: 15.0pt;"&gt;23&lt;/TD&gt;
&lt;TD width="66px" height="15px" align="right"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="61.3333px" height="15px" align="right" style="height: 15.0pt;"&gt;24&lt;/TD&gt;
&lt;TD width="66px" height="15px" align="right"&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="61.3333px" height="15px" align="right" style="height: 15.0pt;"&gt;25&lt;/TD&gt;
&lt;TD width="66px" height="15px" align="right"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="61.3333px" height="15px" align="right" style="height: 15.0pt;"&gt;26&lt;/TD&gt;
&lt;TD width="66px" height="15px" align="right"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to make a new table that groups the age groups by three years and uses the sum of the 'users' variable for that age group. So the output table would look like:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Age_group&amp;nbsp; &amp;nbsp; &amp;nbsp; Users&lt;/P&gt;
&lt;P&gt;17-20&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8&lt;/P&gt;
&lt;P&gt;21-23&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20&lt;/P&gt;
&lt;P&gt;24-26&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does anyone know how to help write the code for this?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 18:36:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Groupings-by-Age/m-p/715856#M27397</guid>
      <dc:creator>marleeakerson</dc:creator>
      <dc:date>2021-02-01T18:36:43Z</dc:date>
    </item>
    <item>
      <title>Re: Groupings by Age</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Groupings-by-Age/m-p/715859#M27398</link>
      <description>&lt;P&gt;How did you get 8 for 17-20? 1+ 2 + 5+ 3 = 11?&lt;BR /&gt;&lt;BR /&gt;Otherwise it just looks like a formatted output.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value age_fmt
17 - 20 = '17 - 20'
21 - 23 = '21 - 23'
24-26 = '24 - 26';
run;

proc freq data=have;
table age ;
weight users;
format age age_fmt.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Fully worked example is available here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/proc_format_example.sas" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/proc_format_example.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/281255"&gt;@marleeakerson&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to group by age and use the sums of the groups. For instance, if I am using this data table:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 96pt;" border="0" width="123px" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="61.3333px" height="15px" style="height: 15.0pt; width: 48pt;"&gt;Age&lt;/TD&gt;
&lt;TD width="66px" height="15px" style="width: 48pt;"&gt;Users&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="61.3333px" height="15px" align="right" style="height: 15.0pt;"&gt;17&lt;/TD&gt;
&lt;TD width="66px" height="15px" align="right"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="61.3333px" height="15px" align="right" style="height: 15.0pt;"&gt;18&lt;/TD&gt;
&lt;TD width="66px" height="15px" align="right"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="61.3333px" height="15px" align="right" style="height: 15.0pt;"&gt;19&lt;/TD&gt;
&lt;TD width="66px" height="15px" align="right"&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="61.3333px" height="15px" align="right" style="height: 15.0pt;"&gt;20&lt;/TD&gt;
&lt;TD width="66px" height="15px" align="right"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="61.3333px" height="15px" align="right" style="height: 15.0pt;"&gt;21&lt;/TD&gt;
&lt;TD width="66px" height="15px" align="right"&gt;9&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="61.3333px" height="15px" align="right" style="height: 15.0pt;"&gt;22&lt;/TD&gt;
&lt;TD width="66px" height="15px" align="right"&gt;9&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="61.3333px" height="15px" align="right" style="height: 15.0pt;"&gt;23&lt;/TD&gt;
&lt;TD width="66px" height="15px" align="right"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="61.3333px" height="15px" align="right" style="height: 15.0pt;"&gt;24&lt;/TD&gt;
&lt;TD width="66px" height="15px" align="right"&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="61.3333px" height="15px" align="right" style="height: 15.0pt;"&gt;25&lt;/TD&gt;
&lt;TD width="66px" height="15px" align="right"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="61.3333px" height="15px" align="right" style="height: 15.0pt;"&gt;26&lt;/TD&gt;
&lt;TD width="66px" height="15px" align="right"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to make a new table that groups the age groups by three years and uses the sum of the 'users' variable for that age group. So the output table would look like:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Age_group&amp;nbsp; &amp;nbsp; &amp;nbsp; Users&lt;/P&gt;
&lt;P&gt;17-20&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8&lt;/P&gt;
&lt;P&gt;21-23&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20&lt;/P&gt;
&lt;P&gt;24-26&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does anyone know how to help write the code for this?&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 18:44:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Groupings-by-Age/m-p/715859#M27398</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-02-01T18:44:18Z</dc:date>
    </item>
    <item>
      <title>Re: Groupings by Age</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Groupings-by-Age/m-p/715864#M27399</link>
      <description>&lt;P&gt;Also you say "group by three years" but 17 to 20 is 4: 17, 18, 19 and 20.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A common way to handle such groups in use a custom format and apply the format in the procedures that are used to count things.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
 input Age 	Users;
datalines;
17 	1
18 	2
19 	5
20 	3
21 	9
22 	9
23 	2
24 	5
25 	3
26 	2
;
proc format;
value myagegrp
17-20 = '17 to 20'
21-23 = '21 to 23'
24-26 = '24 to 26'
;
proc freq data=have;
   tables age;
   format age myagegrp.;
   weight users;
run;&lt;/PRE&gt;
&lt;P&gt;A very strong advantage of using this format approach is that you can create multiple formats that are used with the same data as needed.&lt;/P&gt;
&lt;P&gt;The groups created by proc format will be honored by report procedures like Report and Tabulate, and most graphing and analysis procedures.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 18:51:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Groupings-by-Age/m-p/715864#M27399</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-02-01T18:51:57Z</dc:date>
    </item>
  </channel>
</rss>

