<?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: counting number of events by three variables in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/counting-number-of-events-by-three-variables/m-p/612448#M76838</link>
    <description>&lt;P&gt;Yes. Thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&lt;/P&gt;&lt;P&gt;There are years with out the event based on inclusion criteria, however, I cannot think of another method to assign the zero value other than creating a separate data set with state fips, year, sex and age-group then somehow merging or using a conditional statement to keep the zeros.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 17 Dec 2019 16:41:27 GMT</pubDate>
    <dc:creator>psnorrod</dc:creator>
    <dc:date>2019-12-17T16:41:27Z</dc:date>
    <item>
      <title>counting number of events by three variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/counting-number-of-events-by-three-variables/m-p/612223#M76830</link>
      <description>&lt;P&gt;Greetings!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to count the number of events by the following variables: year, sex, and age_group; and can drop the state variable after events are counted. The code below will count the number of events, however, it does not separate counts by age_group. So far it combines some age_groups for each year.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've attached two data sets with "sample1" representing my data and "sample2" representing my desired results.&lt;/P&gt;&lt;P&gt;Finally, the data is all events so there are no "zeros".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data = one;&lt;BR /&gt;by year state;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data two;&lt;BR /&gt;set one;&lt;BR /&gt;by year state ;&lt;BR /&gt;if first.state then count = 0;&lt;BR /&gt;count + 1;&lt;BR /&gt;if last.state;&lt;BR /&gt;keep year count Sex age_group;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you and your help is much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Paul&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2019 21:22:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/counting-number-of-events-by-three-variables/m-p/612223#M76830</guid>
      <dc:creator>psnorrod</dc:creator>
      <dc:date>2019-12-16T21:22:12Z</dc:date>
    </item>
    <item>
      <title>Re: counting number of events by three variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/counting-number-of-events-by-three-variables/m-p/612232#M76831</link>
      <description>&lt;P&gt;Your output Sample2 does not have anything for 2003 with Sex=2 and Age_group=1 but the input data does. So I am going to guess that your 4th line of Sample 2 is &lt;STRONG&gt;supposed to be &lt;/STRONG&gt;2003 Sex=2 and Age_group=1 instead of a second row with Sex=2 and Age_group=2;&lt;/P&gt;
&lt;P&gt;If my belief is correct then one way to get the output you are requesting is&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc summary data= sample1 nway;
   class year sex age_group;
   output out=work.summary (drop=_type_ rename=(_freq_=count));
run;&lt;/PRE&gt;
&lt;P&gt;Though the order will vary a bit from your Sample2.&lt;/P&gt;
&lt;P&gt;Or&lt;/P&gt;
&lt;PRE&gt;proc freq data= tmp2.sample1 noprint;
   tables year*sex*age_group /out=work.freq (drop=percent) ;
run;&lt;/PRE&gt;
&lt;P&gt;Simple counting belongs to Proc Freq /Summary depending on what you want. Proc Sql also does counts&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table work.sql as
   select year, sex, age_group, count(*) as count
   from sample1
   group by year, sex, age_group
   ;
quit;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2019 23:59:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/counting-number-of-events-by-three-variables/m-p/612232#M76831</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-12-16T23:59:07Z</dc:date>
    </item>
    <item>
      <title>Re: counting number of events by three variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/counting-number-of-events-by-three-variables/m-p/612236#M76834</link>
      <description>&lt;P&gt;Thank you ballardw!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately in my attempt at brevity, I was not very clear. "Sample2" is just an example and does not include 2003. My full data set has over 190k events. I need to create a final data file, like sample2 to merge with my denominator data. Ultimately, I'm going to use proc genmod to obtain crude and adjusted rates for each year. I want to use the sex and age_group variables for the adjusted rates. I hope!&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2019 22:03:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/counting-number-of-events-by-three-variables/m-p/612236#M76834</guid>
      <dc:creator>psnorrod</dc:creator>
      <dc:date>2019-12-16T22:03:40Z</dc:date>
    </item>
    <item>
      <title>Re: counting number of events by three variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/counting-number-of-events-by-three-variables/m-p/612272#M76837</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202926"&gt;@psnorrod&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you ballardw!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unfortunately in my attempt at brevity, I was not very clear. "Sample2" is just an example and does not include 2003. My full data set has over 190k events. I need to create a final data file, like sample2 to merge with my denominator data. Ultimately, I'm going to use proc genmod to obtain crude and adjusted rates for each year. I want to use the sex and age_group variables for the adjusted rates. I hope!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In which case you may need to make sure that you have combinations with a 0 count to be complete. If a model is using those variables and one year does not have a combination of values that appear in other years then you may have unexpected results.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Dec 2019 00:03:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/counting-number-of-events-by-three-variables/m-p/612272#M76837</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-12-17T00:03:33Z</dc:date>
    </item>
    <item>
      <title>Re: counting number of events by three variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/counting-number-of-events-by-three-variables/m-p/612448#M76838</link>
      <description>&lt;P&gt;Yes. Thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&lt;/P&gt;&lt;P&gt;There are years with out the event based on inclusion criteria, however, I cannot think of another method to assign the zero value other than creating a separate data set with state fips, year, sex and age-group then somehow merging or using a conditional statement to keep the zeros.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Dec 2019 16:41:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/counting-number-of-events-by-three-variables/m-p/612448#M76838</guid>
      <dc:creator>psnorrod</dc:creator>
      <dc:date>2019-12-17T16:41:27Z</dc:date>
    </item>
  </channel>
</rss>

