<?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: Grabbing observations within a date range from long data in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Grabbing-observations-within-a-date-range-from-long-data/m-p/369727#M65058</link>
    <description>&lt;P&gt;I'm hoping you can answer a post-solution question. Is there a way to add an indicatior to that code? I was hoping to have another indicator that tells me if the office visit was before or after the visit with the diagnosis (i.e. if the office visit occured before I would have place=-1 and if it happened after place=1). I have been messing around with codes but i cant get anything to work!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thank you!&lt;/P&gt;</description>
    <pubDate>Thu, 22 Jun 2017 22:23:27 GMT</pubDate>
    <dc:creator>sasuser31</dc:creator>
    <dc:date>2017-06-22T22:23:27Z</dc:date>
    <item>
      <title>Grabbing observations within a date range from long data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Grabbing-observations-within-a-date-range-from-long-data/m-p/367150#M64900</link>
      <description>&lt;P&gt;Dealing mainly with the following varaibles:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Case_ind&lt;/P&gt;&lt;P&gt;Dateofvisit&lt;/P&gt;&lt;P&gt;PersonID&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What i have done is define with other variables whether or not a doctor visit was related to my condition of interest (Case_ind 0/1). Now i need to pull out all other visits for the same person that are within 3 weeks before or after the visit for the condititon of interest (case_ind=1). I know how to do this with only 3 weeks after by using a retain statement in a data set by personID, dateofvisit, and case_ind but I am not sure how to grab the ones 3 weeks before?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated!!&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2017 21:40:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Grabbing-observations-within-a-date-range-from-long-data/m-p/367150#M64900</guid>
      <dc:creator>sasuser31</dc:creator>
      <dc:date>2017-06-14T21:40:27Z</dc:date>
    </item>
    <item>
      <title>Re: Grabbing observations within a date range from long data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Grabbing-observations-within-a-date-range-from-long-data/m-p/367153#M64901</link>
      <description>&lt;P&gt;Can you provide an example of the dataset you have, and (based on that example) what you want?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can probably do it using a DOW loop, but I'd rather see what you have before suggesting code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2017 22:00:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Grabbing-observations-within-a-date-range-from-long-data/m-p/367153#M64901</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-06-14T22:00:20Z</dc:date>
    </item>
    <item>
      <title>Re: Grabbing observations within a date range from long data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Grabbing-observations-within-a-date-range-from-long-data/m-p/367161#M64902</link>
      <description>&lt;P&gt;Here is a very simple example of what I am looking for (data&amp;nbsp;are confidential so I cannot provide an actual example).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Input data set:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;OBS ID&lt;/TD&gt;&lt;TD&gt;Case_ind&lt;/TD&gt;&lt;TD&gt;Dateofvisit&lt;/TD&gt;&lt;TD&gt;Personid&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD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;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;4/3/2017&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;4/3/2017&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;4/4/2017&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;4/20/2017&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This process would need to be repeated for all of the people in the dataset. One thing I should mention is someone could have a case of the condition more than once, so we would need to take out the observations that are within 3 weeks of both cases even though they are for the same person.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!!&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2017 22:30:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Grabbing-observations-within-a-date-range-from-long-data/m-p/367161#M64902</guid>
      <dc:creator>sasuser31</dc:creator>
      <dc:date>2017-06-14T22:30:15Z</dc:date>
    </item>
    <item>
      <title>Re: Grabbing observations within a date range from long data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Grabbing-observations-within-a-date-range-from-long-data/m-p/367887#M64951</link>
      <description>&lt;P&gt;Since you said you have the 3 week time period after the condition of interest handled, you can do a similar process for the 3 weeks before.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As of now, the data is sorted by&amp;nbsp;&lt;SPAN&gt;PersonID and&amp;nbsp;Dateofvisit. &amp;nbsp;You need to sort by&amp;nbsp;PersonID and descending Dateofvisit and repeat the methodology you used to pull of the visits within 3 weeks. This will get the 3 weeks prior to the condition of interest.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I.e.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;proc data data = test out = reverse_order;&lt;BR /&gt;by PersonID descending Dateofvisit;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*Add the code you used to pull out the other visits within the 3 weeks time period backward;&lt;BR /&gt;data filter_3weeks_prior_condition;&lt;BR /&gt;set reverse_order;&lt;BR /&gt;/*Filter dataset here*/&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*Then, stack the 2 pulled out datasets, 3 weeks forward and 3 weeks backward;&lt;BR /&gt;data entire_condition_period;&lt;BR /&gt;set filter_3weeks_prior_condition&lt;BR /&gt;filter_3weeks_after_condition /*Your 3 weeks after condition dataset*/;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*Sort the data again to get into proper order (ascending);&lt;BR /&gt;proc sort data = entire_condition_period;&lt;BR /&gt;by PersonID Dateofvisit;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You will now have all of the visits 3 weeks prior and after for the IDs with the condition of interest.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jun 2017 20:53:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Grabbing-observations-within-a-date-range-from-long-data/m-p/367887#M64951</guid>
      <dc:creator>Rwon</dc:creator>
      <dc:date>2017-06-16T20:53:49Z</dc:date>
    </item>
    <item>
      <title>Re: Grabbing observations within a date range from long data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Grabbing-observations-within-a-date-range-from-long-data/m-p/367906#M64952</link>
      <description>&lt;PRE&gt;data have;
   informat obsid Case_ind best. Dateofvisit mmddyy10. Personid best.;
   format Dateofvisit mmddyy10. ; 
   input obsid Case_ind Dateofvisit Personid ;
datalines;
1 0 1/1/2017 1 
2 0 1/4/2017 1 
3 0 2/1/2017 1 
4 0 3/20/2017 1 
5 0 3/24/2017 1 
6 1 4/3/2017 1 
7 0 4/3/2017 1 
8 0 4/4/2017 1 
9 0 4/20/2017 1 
10 0 5/11/2017 1 
11 0 5/31/2017 1 
12 0 7/25/2017 1 
13 0 9/1/2017 1 
14 0 9/2/2017 1 
;
run;

proc sql;
   create table want as
   select b.*
   from (select * from have where case_ind=1) as a
        left join
        have as b
        on a.Personid=b.Personid
   where b.dateofvisit between intnx('week',a.dateofvisit,-3,'s') and 
                               intnx('week',a.dateofvisit,+3,'s')
   order by b.personid,b.Dateofvisit
   ;
quit;&lt;/PRE&gt;
&lt;P&gt;Should do the basic time request.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will have to provide an exampled data set, in the form of a data step similar to above, with an example of that "One thing I should mention is someone could have a case of the condition more than once, so we would need to take out the observations that are within 3 weeks of both cases even though they are for the same person." AND exactly what the result should look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are so many ways that dates could overlap that you may be providing a number of examples. I'm envisioning Case_ind at two week intervals two or more times.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It may be that all that would be needed is Select Distinct b.* in the code above to remove duplicates depending on what your overlap rules actually entail.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jun 2017 22:57:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Grabbing-observations-within-a-date-range-from-long-data/m-p/367906#M64952</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-06-16T22:57:31Z</dc:date>
    </item>
    <item>
      <title>Re: Grabbing observations within a date range from long data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Grabbing-observations-within-a-date-range-from-long-data/m-p/369249#M65030</link>
      <description>This worked! Sorry for the late response, testing the code out on my huge dataset took awhile. Multiple cases for a person had to be six weeks apart, so this code works with the multiple case scenario. Thank you so much!!!!</description>
      <pubDate>Wed, 21 Jun 2017 18:07:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Grabbing-observations-within-a-date-range-from-long-data/m-p/369249#M65030</guid>
      <dc:creator>sasuser31</dc:creator>
      <dc:date>2017-06-21T18:07:30Z</dc:date>
    </item>
    <item>
      <title>Re: Grabbing observations within a date range from long data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Grabbing-observations-within-a-date-range-from-long-data/m-p/369727#M65058</link>
      <description>&lt;P&gt;I'm hoping you can answer a post-solution question. Is there a way to add an indicatior to that code? I was hoping to have another indicator that tells me if the office visit was before or after the visit with the diagnosis (i.e. if the office visit occured before I would have place=-1 and if it happened after place=1). I have been messing around with codes but i cant get anything to work!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 22:23:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Grabbing-observations-within-a-date-range-from-long-data/m-p/369727#M65058</guid>
      <dc:creator>sasuser31</dc:creator>
      <dc:date>2017-06-22T22:23:27Z</dc:date>
    </item>
  </channel>
</rss>

