<?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: finding values happened 30 days before a reference date and 30 days after another in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/finding-values-happened-30-days-before-a-reference-date-and-30/m-p/250002#M47104</link>
    <description>&lt;P&gt;I just relaized the data was truncated post h_date, the second code worked. Thank you&lt;/P&gt;</description>
    <pubDate>Sun, 14 Feb 2016 20:34:02 GMT</pubDate>
    <dc:creator>lillymaginta</dc:creator>
    <dc:date>2016-02-14T20:34:02Z</dc:date>
    <item>
      <title>finding values happened 30 days before a reference date and 30 days after another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/finding-values-happened-30-days-before-a-reference-date-and-30/m-p/249922#M47084</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;id     d_date        rx_name       rx_date                   h_date
1      3/2/2005          a                    3/4/2005                 2/29/2005
1                        b                    4/4/2005
1                        c                    2/25/2005
1                        d 
1                        e
1
1
1
1
2
2
2
2
3
3
3&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have the following data where h_date is hospitalization date and d_date is discharge date. Each rx_name happen in the corresponding rx_Date. I am trying to find rx_name that happened within 30 day before h_date. Also, I want seperately to find rx_name that happaned within 30 days after d_date.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Sun, 14 Feb 2016 01:57:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/finding-values-happened-30-days-before-a-reference-date-and-30/m-p/249922#M47084</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2016-02-14T01:57:17Z</dc:date>
    </item>
    <item>
      <title>Re: finding values happened 30 days before a reference date and 30 days after another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/finding-values-happened-30-days-before-a-reference-date-and-30/m-p/249931#M47085</link>
      <description>&lt;P&gt;Please post a sample of your desired output.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Feb 2016 03:15:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/finding-values-happened-30-days-before-a-reference-date-and-30/m-p/249931#M47085</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-02-14T03:15:15Z</dc:date>
    </item>
    <item>
      <title>Re: finding values happened 30 days before a reference date and 30 days after another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/finding-values-happened-30-days-before-a-reference-date-and-30/m-p/249932#M47086</link>
      <description>&lt;P&gt;I want two seperate datasets;&lt;/P&gt;&lt;P&gt;dataset A, rx_name within 30 days before d_date&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id &amp;nbsp;rx_name&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; c&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dataset b, rx_name within 30 days post :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id rx_name&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; a&lt;/P&gt;</description>
      <pubDate>Sun, 14 Feb 2016 03:38:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/finding-values-happened-30-days-before-a-reference-date-and-30/m-p/249932#M47086</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2016-02-14T03:38:57Z</dc:date>
    </item>
    <item>
      <title>Re: finding values happened 30 days before a reference date and 30 days after another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/finding-values-happened-30-days-before-a-reference-date-and-30/m-p/249935#M47087</link>
      <description>&lt;P&gt;Your requirements aren't consistent between your first post, last post and your output.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That being said, this is how I would do it. First I'd create separate tables for my discharge and hospitalization data. &amp;nbsp;Then I'd use SQL to do the join conditons. This method is more effectie when you have multiple hospitalizations and discharge dates per ID. You haven't shown that, but that's the usual structure for this type of data. I'll leave the data separation as an exercise for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The sample code below finds a drugs with a date 30 days before hospitalization, in a table called PRE30&lt;/P&gt;
&lt;P&gt;and any drugs 30 days after discharge, called POST30. You may want to verify the conditons are what you want, I didn't understand your requirements. You can modify the WHERE condition to match your needs, and I would consider changing the LT and GT to LE and GE, but again, that depends on your requirements.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data hosp;
informat h_date mmddyy10.;
format h_date date9.;
input id $ h_date;
cards;
1 2/28/2005
;
run;

data disch;
informat d_date mmddyy10.;
format d_date date9.;
input id $ d_date;
cards;
1 3/2/2005
;
run;

data drugs;
informat rx_date mmddyy10.;
format rx_date date9.;
input id $ rx $ rx_date;
cards;
1 A 3/4/2005
1 B 4/4/2005
1 D 2/25/2005
;
run;

proc sql;
create table pre30 as
select a.Id, b.rx, b.rx_date, a.h_date, a.h_date-b.rx_date as days_before_hosp
from hosp as a
join drugs as b
on a.id=b.id
where 0&amp;lt; (a.h_date-b.rx_date) &amp;lt; 30;
quit;

proc sql;
create table post30 as
select a.Id, b.rx, b.rx_date, a.d_date, b.rx_date-a.d_date as days_after_disch
from disch as a
join drugs as b
on a.id=b.id
where 0&amp;lt; (b.rx_date-a.d_date) &amp;lt; 30;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 14 Feb 2016 03:59:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/finding-values-happened-30-days-before-a-reference-date-and-30/m-p/249935#M47087</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-02-14T03:59:48Z</dc:date>
    </item>
    <item>
      <title>Re: finding values happened 30 days before a reference date and 30 days after another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/finding-values-happened-30-days-before-a-reference-date-and-30/m-p/249965#M47096</link>
      <description>&lt;P&gt;Thanks Reeza, this is exactly what I wanted which is rx during the 30 days pre and rx within the 30 days post. I tried it and it works perfect! Lilly&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Feb 2016 15:14:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/finding-values-happened-30-days-before-a-reference-date-and-30/m-p/249965#M47096</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2016-02-14T15:14:02Z</dc:date>
    </item>
    <item>
      <title>Re: finding values happened 30 days before a reference date and 30 days after another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/finding-values-happened-30-days-before-a-reference-date-and-30/m-p/249967#M47097</link>
      <description>&lt;P&gt;One issue with the code, it produces duplicates of the same id-rx combination for the same rx_date;&lt;/P&gt;&lt;P&gt;id &amp;nbsp;rx_name &amp;nbsp; rx_Date&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; a &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 05/01/2004&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; a &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;05/01/2004&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; a &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;05/01/2004&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to proc sort nodupkey by id, rx_name after the code you provided but is there a way to avoid this from the first place? thanks!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Feb 2016 15:47:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/finding-values-happened-30-days-before-a-reference-date-and-30/m-p/249967#M47097</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2016-02-14T15:47:48Z</dc:date>
    </item>
    <item>
      <title>Re: finding values happened 30 days before a reference date and 30 days after another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/finding-values-happened-30-days-before-a-reference-date-and-30/m-p/249970#M47098</link>
      <description>&lt;P&gt;The first part of the code works but the second part does not work, return 0 observations:&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;sql&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
create &lt;SPAN class="token statement"&gt;table&lt;/SPAN&gt; post30 as
&lt;SPAN class="token statement"&gt;select&lt;/SPAN&gt; a&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;Id&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; b&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;rx&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; b&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;rx_date&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; a&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;d_date&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; b&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;rx_date&lt;SPAN class="token operator"&gt;-&lt;/SPAN&gt;a&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;d_date as days_after_disch
&lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt; disch as a
join drugs as b
on a&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;id&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;b&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;id&lt;/SPAN&gt;
&lt;SPAN class="token statement"&gt;where&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;0&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;lt;&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;b&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;rx_date&lt;SPAN class="token operator"&gt;-&lt;/SPAN&gt;a&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;d_date&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;lt;&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;30&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;quit&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 14 Feb 2016 16:35:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/finding-values-happened-30-days-before-a-reference-date-and-30/m-p/249970#M47098</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2016-02-14T16:35:25Z</dc:date>
    </item>
    <item>
      <title>Re: finding values happened 30 days before a reference date and 30 days after another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/finding-values-happened-30-days-before-a-reference-date-and-30/m-p/249972#M47100</link>
      <description>Post better sample data - make sure it replicates the issue and I can take a look. Given the sample data the code works.</description>
      <pubDate>Sun, 14 Feb 2016 17:12:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/finding-values-happened-30-days-before-a-reference-date-and-30/m-p/249972#M47100</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-02-14T17:12:11Z</dc:date>
    </item>
    <item>
      <title>Re: finding values happened 30 days before a reference date and 30 days after another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/finding-values-happened-30-days-before-a-reference-date-and-30/m-p/250002#M47104</link>
      <description>&lt;P&gt;I just relaized the data was truncated post h_date, the second code worked. Thank you&lt;/P&gt;</description>
      <pubDate>Sun, 14 Feb 2016 20:34:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/finding-values-happened-30-days-before-a-reference-date-and-30/m-p/250002#M47104</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2016-02-14T20:34:02Z</dc:date>
    </item>
    <item>
      <title>Re: finding values happened 30 days before a reference date and 30 days after another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/finding-values-happened-30-days-before-a-reference-date-and-30/m-p/250473#M47228</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/72105"&gt;@lillymaginta&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;One issue with the code, it produces duplicates of the same id-rx combination for the same rx_date;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/72105"&gt;@lillymaginta&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think, such&amp;nbsp;duplicates can occur&amp;nbsp;if the drug intake happened within the (overlapping) 30-days time windows of two or more hospitalizations. Are the three corresponding H_DATE (or D_DATE) values in your example all the same when you run Reeza's code? Probably not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you don't select H_DATE, D_DATE etc. and you don't need the duplicates, you could use the keyword&amp;nbsp;DISTINCT:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select distinct a.Id, b.rx, b.rx_date&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Feb 2016 23:18:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/finding-values-happened-30-days-before-a-reference-date-and-30/m-p/250473#M47228</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-02-16T23:18:46Z</dc:date>
    </item>
    <item>
      <title>Re: finding values happened 30 days before a reference date and 30 days after another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/finding-values-happened-30-days-before-a-reference-date-and-30/m-p/250475#M47229</link>
      <description>&lt;P&gt;Thank you for the suggesion Freelance&lt;SPAN class="login-bold"&gt;. When I run the code the first time, I realized there was an error in when I processed my subset (millions of records). I have one h_date per patient which mean in the 30 &amp;nbsp;days period, there should be only one rx per rx_date. After I corrected the error, I did not get the duplicates in the second time but thank you for the followup.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;Lilly&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Feb 2016 23:46:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/finding-values-happened-30-days-before-a-reference-date-and-30/m-p/250475#M47229</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2016-02-16T23:46:03Z</dc:date>
    </item>
  </channel>
</rss>

