<?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 Dummy variable dependent on time variable that doesn't include current observation in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Dummy-variable-dependent-on-time-variable-that-doesn-t-include/m-p/546541#M16815</link>
    <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;I have a data set of men (gender =1) and women (gender=0) running 5k runs. I want a dummy that is 1 if a man finished 10 seconds before or 10 seconds after another man, else 0. For women the dummy should just be empty. The 'RunTime' variable is in seconds.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My data looks like this:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.ALLDATA;
  infile datalines dsd truncover;
  input RunDate:MMDDYY10. RunnerID:BEST. Gender:$1. Age:BEST. RunTime:BEST. Placement:BEST.;
  format RunDate MMDDYY10. RunnerID BEST. Age BEST. RunTime BEST. Placement BEST.;
  label RunDate="RunDate" RunnerID="RunnerID" Gender="Gender" Age="Age" RunTime="RunTime" Placement="Placement";
datalines;
10/22/2011 198111 1 39 1102 1
10/22/2011 33415 1 44 1134 2
10/22/2011 196982 1 44 1164 3
10/22/2011 92330 1 24 1182 4
10/22/2011 33809 1 59 1188 5
10/22/2011 79259 1 54 1190 6
10/22/2011 60226 1 59 1210 7
10/22/2011 32065 1 39 1224 8
10/22/2011 134140 1 54 1236 9
10/22/2011 37522 1 44 1247 10
10/22/2011 173019 1 49 1251 11
10/22/2011 186056 0 54 1257 12
10/22/2011 184284 1 34 1275 13
10/22/2011 43517 1 44 1277 14
10/22/2011 39169 1 39 1287 15
10/22/2011 90659 1 39 1346 16
10/22/2011 196665 1 24 1379 17
10/22/2011 36277 1 44 1392 18
10/22/2011 31453 1 49 1394 19
10/22/2011 89064 1 39 1399 20
;;;;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The code i have looks like this. The problem with the code is that is is just comparing the same guys time to his own resulting in the dummy being 1 all the time. Can someone show me how to change the code to get my wanted result?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table DataCTM as
    select 
      *,
      case
        when gender='0' then '.'
        when gender='1' and (select count(*) 
                              from WORK.ALLDATA I 
                              where i.gender='1' 
                              and i.RunDate=o.RunDate 
                              and o.RunTime+10&amp;gt;=i.RunTime and o.RunTime-10&amp;lt;=i.RunTime
                              ) &amp;gt; 0 
                        then '1'
        else '0'
        end
      as CTM
    from WORK.DataCTW O
    ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks in advance for any help you might be able to bring!&lt;/P&gt;</description>
    <pubDate>Wed, 27 Mar 2019 15:00:36 GMT</pubDate>
    <dc:creator>YoLohse</dc:creator>
    <dc:date>2019-03-27T15:00:36Z</dc:date>
    <item>
      <title>Dummy variable dependent on time variable that doesn't include current observation</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Dummy-variable-dependent-on-time-variable-that-doesn-t-include/m-p/546541#M16815</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;I have a data set of men (gender =1) and women (gender=0) running 5k runs. I want a dummy that is 1 if a man finished 10 seconds before or 10 seconds after another man, else 0. For women the dummy should just be empty. The 'RunTime' variable is in seconds.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My data looks like this:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.ALLDATA;
  infile datalines dsd truncover;
  input RunDate:MMDDYY10. RunnerID:BEST. Gender:$1. Age:BEST. RunTime:BEST. Placement:BEST.;
  format RunDate MMDDYY10. RunnerID BEST. Age BEST. RunTime BEST. Placement BEST.;
  label RunDate="RunDate" RunnerID="RunnerID" Gender="Gender" Age="Age" RunTime="RunTime" Placement="Placement";
datalines;
10/22/2011 198111 1 39 1102 1
10/22/2011 33415 1 44 1134 2
10/22/2011 196982 1 44 1164 3
10/22/2011 92330 1 24 1182 4
10/22/2011 33809 1 59 1188 5
10/22/2011 79259 1 54 1190 6
10/22/2011 60226 1 59 1210 7
10/22/2011 32065 1 39 1224 8
10/22/2011 134140 1 54 1236 9
10/22/2011 37522 1 44 1247 10
10/22/2011 173019 1 49 1251 11
10/22/2011 186056 0 54 1257 12
10/22/2011 184284 1 34 1275 13
10/22/2011 43517 1 44 1277 14
10/22/2011 39169 1 39 1287 15
10/22/2011 90659 1 39 1346 16
10/22/2011 196665 1 24 1379 17
10/22/2011 36277 1 44 1392 18
10/22/2011 31453 1 49 1394 19
10/22/2011 89064 1 39 1399 20
;;;;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The code i have looks like this. The problem with the code is that is is just comparing the same guys time to his own resulting in the dummy being 1 all the time. Can someone show me how to change the code to get my wanted result?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table DataCTM as
    select 
      *,
      case
        when gender='0' then '.'
        when gender='1' and (select count(*) 
                              from WORK.ALLDATA I 
                              where i.gender='1' 
                              and i.RunDate=o.RunDate 
                              and o.RunTime+10&amp;gt;=i.RunTime and o.RunTime-10&amp;lt;=i.RunTime
                              ) &amp;gt; 0 
                        then '1'
        else '0'
        end
      as CTM
    from WORK.DataCTW O
    ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks in advance for any help you might be able to bring!&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 15:00:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Dummy-variable-dependent-on-time-variable-that-doesn-t-include/m-p/546541#M16815</guid>
      <dc:creator>YoLohse</dc:creator>
      <dc:date>2019-03-27T15:00:36Z</dc:date>
    </item>
    <item>
      <title>Re: Dummy variable dependent on time variable that doesn't include current observation</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Dummy-variable-dependent-on-time-variable-that-doesn-t-include/m-p/546556#M16819</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/267446"&gt;@YoLohse&lt;/a&gt;&amp;nbsp; Can you please post the wanted result for your sample along with explanation of the logic. I can't see the wanted result&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 15:26:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Dummy-variable-dependent-on-time-variable-that-doesn-t-include/m-p/546556#M16819</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-27T15:26:41Z</dc:date>
    </item>
    <item>
      <title>Re: Dummy variable dependent on time variable that doesn't include current observation</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Dummy-variable-dependent-on-time-variable-that-doesn-t-include/m-p/546793#M16823</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/267446"&gt;@YoLohse&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You simply need to exclude the same rows in the lookup.&lt;/P&gt;
&lt;P&gt;Also using information you've provided here&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Data-Management/Create-dummy-variable-dependent-on-time-interval/m-p/545599#M16794" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Data-Management/Create-dummy-variable-dependent-on-time-interval/m-p/545599#M16794 &lt;/A&gt;column RunnerID should allow for this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table DataCTM as
    select 
      *,
      case
        when gender='0' then '.'
        when gender='1' and (select count(*) 
                              from WORK.ALLDATA I 
                              where i.gender='1' 
                              and i.RunnerID ne o.RunnerID
                              and i.RunDate=o.RunDate 
                              and o.RunTime+10&amp;gt;=i.RunTime and o.RunTime-10&amp;lt;=i.RunTime
                              ) &amp;gt; 0 
                        then '1'
        else '0'
        end
      as CTM
    from WORK.DataCTW O
    ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2019 06:19:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Dummy-variable-dependent-on-time-variable-that-doesn-t-include/m-p/546793#M16823</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-03-28T06:19:05Z</dc:date>
    </item>
    <item>
      <title>Re: Dummy variable dependent on time variable that doesn't include current observation</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Dummy-variable-dependent-on-time-variable-that-doesn-t-include/m-p/547495#M16832</link>
      <description>Thank you very much! Can you also alter the code to make a count variable, that counts the number of people finishing withing plus/minus 10 seconds of a runner?</description>
      <pubDate>Sun, 31 Mar 2019 15:42:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Dummy-variable-dependent-on-time-variable-that-doesn-t-include/m-p/547495#M16832</guid>
      <dc:creator>YoLohse</dc:creator>
      <dc:date>2019-03-31T15:42:14Z</dc:date>
    </item>
  </channel>
</rss>

