<?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 the number of observations within a time frame in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Counting-the-number-of-observations-within-a-time-frame/m-p/565593#M75043</link>
    <description>PROC FREQ also generates a cumulative statistics - check the output options.</description>
    <pubDate>Wed, 12 Jun 2019 15:23:38 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-06-12T15:23:38Z</dc:date>
    <item>
      <title>Counting the number of observations within a time frame</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counting-the-number-of-observations-within-a-time-frame/m-p/565579#M75038</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have read a few posts about this, but none of the codes work for what I am trying to do and I am not well-versed enough in proc sql to figure out how to tweak them correctly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to prepare data for run charts and study process metrics for a clinical trial. I need to calculate the number of providers enrolled at each month in this study (cumulative). I coded it so that I have which month the provider enrolled in the study and I basically need to calculate how many providers are enrolled during month 1, month 2, month 3, etc. So there are 3 providers enrolled at month 1, and 2 more enroll during month 2. The number of enrolled providers for month 2 would then be 5 (3 enrolled month 1, 2 enrolled month 2). I need a code to calculate the number enrolled per month, cumulatively, and output this as a new variable. It would also be great to be able to get this number by site.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For reference this is what my data looks like:&amp;nbsp;&lt;/P&gt;&lt;P&gt;username&amp;nbsp; &amp;nbsp; &amp;nbsp; site&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;month&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;user1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;117&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;user2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;117&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;user3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;117&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;user4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;104&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;user5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;104&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;user6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;104&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;user7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;104&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;user8&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;110&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;user9&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;110&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;user10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;114&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;user11&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 114&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;&lt;P&gt;user12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 117&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2019 15:04:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counting-the-number-of-observations-within-a-time-frame/m-p/565579#M75038</guid>
      <dc:creator>fordcr2</dc:creator>
      <dc:date>2019-06-12T15:04:18Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observations within a time frame</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counting-the-number-of-observations-within-a-time-frame/m-p/565585#M75040</link>
      <description>&lt;P&gt;Is provider the same as username? Can a provider be listed more than once?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* First get non-cumulative results */
proc summary data=have nway;
    class site month;
    var month;
    output out=counts n=count;
run;

/* Next get cumulative results */
data want;
    set counts;
    by site;
    if first.site then cumulative=0;
    cumulative+count;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2019 15:19:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counting-the-number-of-observations-within-a-time-frame/m-p/565585#M75040</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-06-12T15:19:05Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observations within a time frame</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counting-the-number-of-observations-within-a-time-frame/m-p/565590#M75041</link>
      <description>&lt;P&gt;Providers are only listed once, so the usernames are unique and serve as the providerid. And that worked! With the minor substitution of set counts instead of set want. Thank you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2019 15:16:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counting-the-number-of-observations-within-a-time-frame/m-p/565590#M75041</guid>
      <dc:creator>fordcr2</dc:creator>
      <dc:date>2019-06-12T15:16:07Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observations within a time frame</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counting-the-number-of-observations-within-a-time-frame/m-p/565591#M75042</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/255164"&gt;@fordcr2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;With the minor substitution of set counts instead of set want.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yep. My bad! I went back and made the correction.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2019 15:18:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counting-the-number-of-observations-within-a-time-frame/m-p/565591#M75042</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-06-12T15:18:38Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observations within a time frame</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counting-the-number-of-observations-within-a-time-frame/m-p/565593#M75043</link>
      <description>PROC FREQ also generates a cumulative statistics - check the output options.</description>
      <pubDate>Wed, 12 Jun 2019 15:23:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counting-the-number-of-observations-within-a-time-frame/m-p/565593#M75043</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-06-12T15:23:38Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observations within a time frame</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counting-the-number-of-observations-within-a-time-frame/m-p/565594#M75044</link>
      <description>&lt;P&gt;I know but I needed it in the actual dataset as a variable to be exported - didn't know how to make the cumulative number from proc freq into an output.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2019 15:24:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counting-the-number-of-observations-within-a-time-frame/m-p/565594#M75044</guid>
      <dc:creator>fordcr2</dc:creator>
      <dc:date>2019-06-12T15:24:46Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observations within a time frame</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counting-the-number-of-observations-within-a-time-frame/m-p/565597#M75046</link>
      <description>&lt;P&gt;In my example, you could easily replace PROC SUMMARY with PROC FREQ to get non-cumulative results, then the same method to get cumulative results, although I leave the issue of writing the actual code to others.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2019 15:30:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counting-the-number-of-observations-within-a-time-frame/m-p/565597#M75046</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-06-12T15:30:12Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observations within a time frame</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counting-the-number-of-observations-within-a-time-frame/m-p/565600#M75047</link>
      <description>&lt;P&gt;Got it. I actually used proc summary to get the total number of providers across all sites using your code to get the cumulative numbers per site, and then proc summary to total of those numbers for the overall cumulative number.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2019 15:32:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counting-the-number-of-observations-within-a-time-frame/m-p/565600#M75047</guid>
      <dc:creator>fordcr2</dc:creator>
      <dc:date>2019-06-12T15:32:44Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observations within a time frame</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counting-the-number-of-observations-within-a-time-frame/m-p/565703#M75050</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/255164"&gt;@fordcr2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I know but I needed it in the actual dataset as a variable to be exported - didn't know how to make the cumulative number from proc freq into an output.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Example using the OUTCUM option to get cumulative totals.&lt;/P&gt;
&lt;PRE&gt;proc freq data = sashelp.class noprint;
   tables age/ out=work.freq outcum ;
run;&lt;/PRE&gt;
&lt;P&gt;However that only works on one-way tables since the concept of "cumulative" gets interesting in multidimensional (2 or more variables) terms.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2019 22:24:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counting-the-number-of-observations-within-a-time-frame/m-p/565703#M75050</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-06-12T22:24:32Z</dc:date>
    </item>
  </channel>
</rss>

