<?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 Create a binary variable from two data files in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/Create-a-binary-variable-from-two-data-files/m-p/426718#M4302</link>
    <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have&amp;nbsp;two data files that include patients' information on (1) the dose and duration of medications they take, and (2) whether or not they have had hospital readmissions. Here are parts of these data files (extracted for just one patient):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data drug;
input id dose_drug1 dose_drug2 date_start date_stop;
datalines;
1 7.5 5 01/17/2008 03/16/2008
1 22.5 3 03/20/2008 04/01/2008
1 30 8.5 08/07/2008 08/22/2008
1 15 5 11/23/2008 12/22/2008
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data readmission;
input id readm_number date;
datalines;
1 1 02/20/2008
1 2 05/03/2008
1 3 07/10/2008
1 4 09/28/2008
1 5 11/09/2008
1 6 12/06/2008
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;Now, I want to create another data file with&amp;nbsp;new variables including dose of drug 1, dose of drug 2, duration of supply, and an indicator variable that takes binary (i.e., 0/1) values, where 1 implies that a hospital readmission occurred within a time window (e.g., 30 days, 60 days, etc.) after the drug supply. For example, for the case of&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;U&gt;30-day time window&lt;/U&gt;&lt;/STRONG&gt;&lt;SPAN&gt;, here is what I'm looking for:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want_time_window_30;
input id dose_drug1 dose_drug2 duration indicator event_date;
datalines;
1 7.5 5 34 1 02/20/2008
1 7.5 5 25 0 .
1 22.5 3 12 0 .
1 30 8.5 15 0 .
1 15 5 13 1 12/06/2008
1 15 5 16 0 .
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;For example, the first event (i.e., hospital readmission) occurs on 02/20, which is in the middle of the first drug supply (from 01/17 to 03/16). That's why the duration (in the first line) becomes 34 days = 02/20-01/17.&amp;nbsp;But, I still have drug supply after 02/20 (until 03/16). That's why I have&amp;nbsp;the second line with the same drug dose, but with a different duration 25 days = 03/16-02/20 (also, the indicator variable is different between these two lines).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;For your convenience, I provided the following time frame where the brackets represent drug supply periods (with the dose of drugs underneath), and vertical arrows represent the time of hospital readmissions.&lt;/SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Untitled.jpg" style="width: 535px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/17778iEACFF87D2F12910A/image-dimensions/535x248?v=v2" width="535" height="248" role="button" title="Untitled.jpg" alt="Untitled.jpg" /&gt;&lt;/span&gt;&lt;SPAN&gt;To further clarify, here is what I&amp;nbsp;want for the&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;U&gt;60-day time window&lt;/U&gt;&lt;/STRONG&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want_time_window_60;
input id dose_drug1 dose_drug2 duration indicator event_date;
datalines;
1 7.5 5 34 1 02/20/2008
1 7.5 5 25 1 05/03/2008
1 22.5 3 12 1 05/03/2008
1 30 8.5 15 1 09/28/2008
1 15 5 13 1 12/06/2008
1 15 5 16 0 .
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;Note that, if it is the 90-day time window, the only line that will be added to the lines above (between lines 4 and 5) is as follows:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1 30 8.5 15 1 11/09/2008&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;I tried to be as demonstrative as possible, but if there is anything that should be further clarified, please let me know. Thank you very much, in advance, for your time and help!&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 10 Jan 2018 22:53:34 GMT</pubDate>
    <dc:creator>Alireza_Boloori</dc:creator>
    <dc:date>2018-01-10T22:53:34Z</dc:date>
    <item>
      <title>Create a binary variable from two data files</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Create-a-binary-variable-from-two-data-files/m-p/426718#M4302</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have&amp;nbsp;two data files that include patients' information on (1) the dose and duration of medications they take, and (2) whether or not they have had hospital readmissions. Here are parts of these data files (extracted for just one patient):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data drug;
input id dose_drug1 dose_drug2 date_start date_stop;
datalines;
1 7.5 5 01/17/2008 03/16/2008
1 22.5 3 03/20/2008 04/01/2008
1 30 8.5 08/07/2008 08/22/2008
1 15 5 11/23/2008 12/22/2008
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data readmission;
input id readm_number date;
datalines;
1 1 02/20/2008
1 2 05/03/2008
1 3 07/10/2008
1 4 09/28/2008
1 5 11/09/2008
1 6 12/06/2008
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;Now, I want to create another data file with&amp;nbsp;new variables including dose of drug 1, dose of drug 2, duration of supply, and an indicator variable that takes binary (i.e., 0/1) values, where 1 implies that a hospital readmission occurred within a time window (e.g., 30 days, 60 days, etc.) after the drug supply. For example, for the case of&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;U&gt;30-day time window&lt;/U&gt;&lt;/STRONG&gt;&lt;SPAN&gt;, here is what I'm looking for:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want_time_window_30;
input id dose_drug1 dose_drug2 duration indicator event_date;
datalines;
1 7.5 5 34 1 02/20/2008
1 7.5 5 25 0 .
1 22.5 3 12 0 .
1 30 8.5 15 0 .
1 15 5 13 1 12/06/2008
1 15 5 16 0 .
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;For example, the first event (i.e., hospital readmission) occurs on 02/20, which is in the middle of the first drug supply (from 01/17 to 03/16). That's why the duration (in the first line) becomes 34 days = 02/20-01/17.&amp;nbsp;But, I still have drug supply after 02/20 (until 03/16). That's why I have&amp;nbsp;the second line with the same drug dose, but with a different duration 25 days = 03/16-02/20 (also, the indicator variable is different between these two lines).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;For your convenience, I provided the following time frame where the brackets represent drug supply periods (with the dose of drugs underneath), and vertical arrows represent the time of hospital readmissions.&lt;/SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Untitled.jpg" style="width: 535px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/17778iEACFF87D2F12910A/image-dimensions/535x248?v=v2" width="535" height="248" role="button" title="Untitled.jpg" alt="Untitled.jpg" /&gt;&lt;/span&gt;&lt;SPAN&gt;To further clarify, here is what I&amp;nbsp;want for the&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;U&gt;60-day time window&lt;/U&gt;&lt;/STRONG&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want_time_window_60;
input id dose_drug1 dose_drug2 duration indicator event_date;
datalines;
1 7.5 5 34 1 02/20/2008
1 7.5 5 25 1 05/03/2008
1 22.5 3 12 1 05/03/2008
1 30 8.5 15 1 09/28/2008
1 15 5 13 1 12/06/2008
1 15 5 16 0 .
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;Note that, if it is the 90-day time window, the only line that will be added to the lines above (between lines 4 and 5) is as follows:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1 30 8.5 15 1 11/09/2008&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;I tried to be as demonstrative as possible, but if there is anything that should be further clarified, please let me know. Thank you very much, in advance, for your time and help!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2018 22:53:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Create-a-binary-variable-from-two-data-files/m-p/426718#M4302</guid>
      <dc:creator>Alireza_Boloori</dc:creator>
      <dc:date>2018-01-10T22:53:34Z</dc:date>
    </item>
    <item>
      <title>Re: Create a binary variable from two data files</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Create-a-binary-variable-from-two-data-files/m-p/426952#M4310</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/147550"&gt;@Alireza_Boloori&lt;/a&gt;&amp;nbsp;I really need some further clarification on the data. OK, How would you lookup/join drug and readmission. The following is the output if you look up using merge by id, however when the merge statement processes the readmission #4(4th obs with drug, this will result in one to many merge as you see the below output table. You need to lead me from here.&lt;/P&gt;&lt;P&gt;/*trying to lookup*/&lt;/P&gt;&lt;P&gt;data lookup;&lt;BR /&gt;merge drug readmission;&lt;BR /&gt;by id;&lt;BR /&gt;interval_datestart_date=intck('day', date_start, date);&lt;BR /&gt;interval_datestop_date=intck('day', date, date_stop);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Result of &lt;SPAN&gt;lookup:&lt;/SPAN&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;id&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;dose_drug1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;dose_drug2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;date_start&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;date_stop&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;readm_number&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;date&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;interval_datestart_date&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;interval_datestop_date&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;7.5&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;1/17/2008&lt;/TD&gt;&lt;TD&gt;3/16/2008&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2/20/2008&lt;/TD&gt;&lt;TD&gt;34&lt;/TD&gt;&lt;TD&gt;25&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;22.5&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;3/20/2008&lt;/TD&gt;&lt;TD&gt;4/1/2008&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;5/3/2008&lt;/TD&gt;&lt;TD&gt;44&lt;/TD&gt;&lt;TD&gt;-32&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&g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
      <pubDate>Thu, 11 Jan 2018 18:40:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Create-a-binary-variable-from-two-data-files/m-p/426952#M4310</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-11T18:40:25Z</dc:date>
    </item>
    <item>
      <title>Re: Create a binary variable from two data files</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Create-a-binary-variable-from-two-data-files/m-p/427462#M4316</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;Thanks for your thoughts! I had to add many other steps to it. The thing I was looking for was more detailed and complicated than I originally thought.&lt;/P&gt;</description>
      <pubDate>Sat, 13 Jan 2018 20:00:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Create-a-binary-variable-from-two-data-files/m-p/427462#M4316</guid>
      <dc:creator>Alireza_Boloori</dc:creator>
      <dc:date>2018-01-13T20:00:46Z</dc:date>
    </item>
    <item>
      <title>Re: Create a binary variable from two data files</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Create-a-binary-variable-from-two-data-files/m-p/427466#M4317</link>
      <description>&lt;P&gt;Alright. Should you have a clear flow of logic at any point ,repost your needs again.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 13 Jan 2018 20:27:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Create-a-binary-variable-from-two-data-files/m-p/427466#M4317</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-13T20:27:59Z</dc:date>
    </item>
  </channel>
</rss>

