<?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: Scanning observations with an hour of a flag variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Scanning-observations-with-an-hour-of-a-flag-variable/m-p/722472#M224013</link>
    <description>&lt;P&gt;There could be many approaches to this issue.&lt;BR /&gt;What I am trying to do is compare all alarm1 and alarm2 for the same ptID and where the the alarm2 occurred within the prior 60 min (i.e 3600 seconds).&lt;BR /&gt;Here is my code&lt;/P&gt;&lt;PRE&gt;data test;&lt;BR /&gt;informat Time anydtdtm15.;&lt;BR /&gt;format Time datetime15.;&lt;BR /&gt;input ptID Alarm1  Alarm2 Time;&lt;BR /&gt;datalines;&lt;BR /&gt;01      0           1      02APR08:20:00&lt;BR /&gt;01      0           0      02APR08:22:15&lt;BR /&gt;01      1           0      02APR08:22:25&lt;BR /&gt;;;&lt;BR /&gt;run;&lt;BR /&gt;data test1 (rename=(Time=time1));&lt;BR /&gt;set test( drop=alarm2);&lt;BR /&gt;if alarm1;&lt;BR /&gt;run;&lt;BR /&gt;data test2(rename=(Time=time2) );;&lt;BR /&gt;set test(drop=alarm1);&lt;BR /&gt;if alarm2;&lt;BR /&gt;run;&lt;BR /&gt;proc sql;&lt;BR /&gt;select a.ptid, a.alarm1, b.alarm2, (a.time1-b.time2) as difftime&lt;BR /&gt;from test1 a cross join test2 b &lt;BR /&gt;where a.ptid=b.ptid&lt;BR /&gt;AND  (a.time1-b.time2) ge 3600;&lt;BR /&gt;quit;&lt;/PRE&gt;&lt;P&gt;Please let me know if you have questions.&lt;/P&gt;</description>
    <pubDate>Sun, 28 Feb 2021 19:58:14 GMT</pubDate>
    <dc:creator>Sajid01</dc:creator>
    <dc:date>2021-02-28T19:58:14Z</dc:date>
    <item>
      <title>Scanning observations with an hour of a flag variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Scanning-observations-with-an-hour-of-a-flag-variable/m-p/722382#M223980</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; I have a dataset similar to the one below. For all cases where there is an Alarm1, I want to find out if an Alarm2 occurred within 60 minutes PRIOR to the Alarm1. Hope this makes sense &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; I have tried using intck and intnx functions, but they always return one record. I can't find a way to scan all records that are 60 minutes PRIOR, when Alarm1 =1. Any ideas on how to make it work? Thanks so much!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ptID Alarm1&amp;nbsp; Alarm2 Time&lt;/P&gt;&lt;P&gt;01&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;02APR08: 22:10&lt;/P&gt;&lt;P&gt;01&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; 02APR08: 22:15&lt;/P&gt;&lt;P&gt;01&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; 02APR08: 22:25&lt;/P&gt;</description>
      <pubDate>Sun, 28 Feb 2021 02:30:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Scanning-observations-with-an-hour-of-a-flag-variable/m-p/722382#M223980</guid>
      <dc:creator>Abishekaa</dc:creator>
      <dc:date>2021-02-28T02:30:13Z</dc:date>
    </item>
    <item>
      <title>Re: Scanning observations with an hour of a flag variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Scanning-observations-with-an-hour-of-a-flag-variable/m-p/722393#M223983</link>
      <description>&lt;P&gt;And do what? Flag all observations for piID = '01'?&lt;/P&gt;</description>
      <pubDate>Sun, 28 Feb 2021 06:54:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Scanning-observations-with-an-hour-of-a-flag-variable/m-p/722393#M223983</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-28T06:54:07Z</dc:date>
    </item>
    <item>
      <title>Re: Scanning observations with an hour of a flag variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Scanning-observations-with-an-hour-of-a-flag-variable/m-p/722426#M223988</link>
      <description>Yes, flag observations by PtID and Date &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Sun, 28 Feb 2021 15:56:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Scanning-observations-with-an-hour-of-a-flag-variable/m-p/722426#M223988</guid>
      <dc:creator>Abishekaa</dc:creator>
      <dc:date>2021-02-28T15:56:41Z</dc:date>
    </item>
    <item>
      <title>Re: Scanning observations with an hour of a flag variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Scanning-observations-with-an-hour-of-a-flag-variable/m-p/722472#M224013</link>
      <description>&lt;P&gt;There could be many approaches to this issue.&lt;BR /&gt;What I am trying to do is compare all alarm1 and alarm2 for the same ptID and where the the alarm2 occurred within the prior 60 min (i.e 3600 seconds).&lt;BR /&gt;Here is my code&lt;/P&gt;&lt;PRE&gt;data test;&lt;BR /&gt;informat Time anydtdtm15.;&lt;BR /&gt;format Time datetime15.;&lt;BR /&gt;input ptID Alarm1  Alarm2 Time;&lt;BR /&gt;datalines;&lt;BR /&gt;01      0           1      02APR08:20:00&lt;BR /&gt;01      0           0      02APR08:22:15&lt;BR /&gt;01      1           0      02APR08:22:25&lt;BR /&gt;;;&lt;BR /&gt;run;&lt;BR /&gt;data test1 (rename=(Time=time1));&lt;BR /&gt;set test( drop=alarm2);&lt;BR /&gt;if alarm1;&lt;BR /&gt;run;&lt;BR /&gt;data test2(rename=(Time=time2) );;&lt;BR /&gt;set test(drop=alarm1);&lt;BR /&gt;if alarm2;&lt;BR /&gt;run;&lt;BR /&gt;proc sql;&lt;BR /&gt;select a.ptid, a.alarm1, b.alarm2, (a.time1-b.time2) as difftime&lt;BR /&gt;from test1 a cross join test2 b &lt;BR /&gt;where a.ptid=b.ptid&lt;BR /&gt;AND  (a.time1-b.time2) ge 3600;&lt;BR /&gt;quit;&lt;/PRE&gt;&lt;P&gt;Please let me know if you have questions.&lt;/P&gt;</description>
      <pubDate>Sun, 28 Feb 2021 19:58:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Scanning-observations-with-an-hour-of-a-flag-variable/m-p/722472#M224013</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2021-02-28T19:58:14Z</dc:date>
    </item>
  </channel>
</rss>

