<?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 Counting number of date variables within given range in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-date-variables-within-given-range/m-p/52726#M11146</link>
    <description>I have a data set with many sas-date variables that represent dates on which certain events occured for each observation. If the event did not occur, the date variables are missing.&lt;BR /&gt;
&lt;BR /&gt;
To count how many of the events occurred (and create a new variable with this information), I would simply use the N( var1, var2, varN...) function in a data step.&lt;BR /&gt;
&lt;BR /&gt;
Now, if I need to count how many of these events occurred (i.e., how many variables have non-missing values) &lt;I&gt;&lt;/I&gt;&lt;I&gt;within a date range created by other variables&lt;/I&gt;&lt;I&gt;&lt;/I&gt;, can I use the N function nested somehow in an if-then string? Is there another applicable function?&lt;BR /&gt;
&lt;BR /&gt;
The data looks like this if my wording wasn't clear:&lt;BR /&gt;
&lt;BR /&gt;
startdate enddate event1 event2 event3&lt;BR /&gt;
4/12/98   5/15/98  4/14/98       5/26/98     4/30/98&lt;BR /&gt;
&lt;BR /&gt;
And I need to find how many events happened between the startdate and enddate. &lt;BR /&gt;
&lt;BR /&gt;
Thanks</description>
    <pubDate>Mon, 19 Jul 2010 19:57:43 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2010-07-19T19:57:43Z</dc:date>
    <item>
      <title>Counting number of date variables within given range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-date-variables-within-given-range/m-p/52726#M11146</link>
      <description>I have a data set with many sas-date variables that represent dates on which certain events occured for each observation. If the event did not occur, the date variables are missing.&lt;BR /&gt;
&lt;BR /&gt;
To count how many of the events occurred (and create a new variable with this information), I would simply use the N( var1, var2, varN...) function in a data step.&lt;BR /&gt;
&lt;BR /&gt;
Now, if I need to count how many of these events occurred (i.e., how many variables have non-missing values) &lt;I&gt;&lt;/I&gt;&lt;I&gt;within a date range created by other variables&lt;/I&gt;&lt;I&gt;&lt;/I&gt;, can I use the N function nested somehow in an if-then string? Is there another applicable function?&lt;BR /&gt;
&lt;BR /&gt;
The data looks like this if my wording wasn't clear:&lt;BR /&gt;
&lt;BR /&gt;
startdate enddate event1 event2 event3&lt;BR /&gt;
4/12/98   5/15/98  4/14/98       5/26/98     4/30/98&lt;BR /&gt;
&lt;BR /&gt;
And I need to find how many events happened between the startdate and enddate. &lt;BR /&gt;
&lt;BR /&gt;
Thanks</description>
      <pubDate>Mon, 19 Jul 2010 19:57:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-date-variables-within-given-range/m-p/52726#M11146</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-07-19T19:57:43Z</dc:date>
    </item>
    <item>
      <title>Re: Counting number of date variables within given range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-date-variables-within-given-range/m-p/52727#M11147</link>
      <description>You have the INTCK function to consider.  Also, you may want to consider a DO/END loop to check for dates within a low/high range -- consider that SAS numeric DATE variables are represented as "number of days since 1/1/1960".&lt;BR /&gt;
&lt;BR /&gt;
Also, if all analysis is done within one observation, you can look at using your appropriate function, like N, and code this type of assignment statement:&lt;BR /&gt;
&lt;BR /&gt;
34   data _null_;&lt;BR /&gt;
35   input (startdate enddate event1 event2 event3) (mmddyy8.);&lt;BR /&gt;
36   format startdate enddate event: date9.;&lt;BR /&gt;
37   occur = n(of event: );&lt;BR /&gt;
38   putlog _infile_ / _all_;&lt;BR /&gt;
39   datalines;&lt;BR /&gt;
&lt;BR /&gt;
4/12/98 5/15/98 4/14/98 5/26/98 4/30/98&lt;BR /&gt;
startdate=12APR1998 enddate=15MAY1998 event1=14APR1998 event2=26MAY1998 event3=30APR1998 occur=3&lt;BR /&gt;
_ERROR_=0 _INFILE_=4/12/98 5/15/98 4/14/98 5/26/98 4/30/98 _N_=1&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.00 seconds&lt;BR /&gt;
      cpu time            0.00 seconds&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
41   run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Mon, 19 Jul 2010 20:44:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-date-variables-within-given-range/m-p/52727#M11147</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-07-19T20:44:21Z</dc:date>
    </item>
    <item>
      <title>Re: Counting number of date variables within given range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-date-variables-within-given-range/m-p/52728#M11148</link>
      <description>I finally buckled down and learned do loops. Thanks for the advice. &lt;BR /&gt;
&lt;BR /&gt;
td</description>
      <pubDate>Tue, 20 Jul 2010 15:03:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-date-variables-within-given-range/m-p/52728#M11148</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-07-20T15:03:35Z</dc:date>
    </item>
  </channel>
</rss>

