<?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: Proc sql update not working: updating a dataset based on dates in a second dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-update-not-working-updating-a-dataset-based-on-dates-in/m-p/895493#M353815</link>
    <description>&lt;P&gt;Don't use UPDATE.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Seems like a very strange strategy to go to the trouble to make a dataset that you then immediately turn around and try to modify.&amp;nbsp; Just make the dataset you want directly.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table nifgroup.nif2 as 
  select a.*
       , max(b.fill_dt between a.fill_dt - 120 and a.fill_dt) as amlinwash
  from nifgroup.nif1 a
  left join amlgroup.allfills b
    on a.patid = b.patid
  group by a.patid, a.fill_dt
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 22 Sep 2023 18:43:07 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-09-22T18:43:07Z</dc:date>
    <item>
      <title>Proc sql update not working: updating a dataset based on dates in a second dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-update-not-working-updating-a-dataset-based-on-dates-in/m-p/895476#M353808</link>
      <description>&lt;P&gt;I'm having a hard time getting the code below to run at all. I am working with medication fill data, and I have two files which separately list all fills for two different medications. In the dataset 'nif2', I am trying to create a flag to indicate a washout period: within a unique ID, for each fill of medication #1 in 'nif2', I want to see if there is also a fill for medication #2 in 'allfills'&amp;nbsp; in the 120 days preceding the fill in 'nif2'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data nifgroup.nif2;
set nifgroup.nif1;
amlinwash = 0;
run;

proc sql;
update nifgroup.nif2 as a
set amlinwash = 1
where exists 
(select * from amlgroup.allfills as b
where a.patid = b.patid and b.fill_dt &amp;lt;= a.fill_dt and b.fill_dt &amp;gt;= (a.fill_dt -120));
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;When I run this code, it does not stop (even after an unreasonable amount of time). I need to stop the code myself. When I check the log, it shows that it gets to the 'proc sql' step and the first row in 'allfills' is read, but nothing has happened after that. Any suggestions for why the code above is getting stuck is much appreciated.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2023 17:12:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-update-not-working-updating-a-dataset-based-on-dates-in/m-p/895476#M353808</guid>
      <dc:creator>dominiquec</dc:creator>
      <dc:date>2023-09-22T17:12:56Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql update not working: updating a dataset based on dates in a second dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-update-not-working-updating-a-dataset-based-on-dates-in/m-p/895493#M353815</link>
      <description>&lt;P&gt;Don't use UPDATE.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Seems like a very strange strategy to go to the trouble to make a dataset that you then immediately turn around and try to modify.&amp;nbsp; Just make the dataset you want directly.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table nifgroup.nif2 as 
  select a.*
       , max(b.fill_dt between a.fill_dt - 120 and a.fill_dt) as amlinwash
  from nifgroup.nif1 a
  left join amlgroup.allfills b
    on a.patid = b.patid
  group by a.patid, a.fill_dt
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Sep 2023 18:43:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-update-not-working-updating-a-dataset-based-on-dates-in/m-p/895493#M353815</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-22T18:43:07Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql update not working: updating a dataset based on dates in a second dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-update-not-working-updating-a-dataset-based-on-dates-in/m-p/895724#M353900</link>
      <description>&lt;P&gt;Thank you for your help! When I try your code, the number of observations increased (not something I expected). What happened was that for each patid that appears in 'allfills', the number of observations for that individual in 'nif2' is the number of obs in 'nif1' multiplied by the number of obs in 'allfills'.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's a made-up example of what I'm trying to get:&amp;nbsp;&lt;/P&gt;&lt;P&gt;nifgroup.nif1&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;patid&lt;/TD&gt;&lt;TD&gt;fill_dt&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;100100&lt;/TD&gt;&lt;TD&gt;08/05/2019&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;100100&lt;/TD&gt;&lt;TD&gt;09/01/2019&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;100100&lt;/TD&gt;&lt;TD&gt;09/30/2019&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;100100&lt;/TD&gt;&lt;TD&gt;10/28/2019&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;100100&lt;/TD&gt;&lt;TD&gt;11/29/2019&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;amlgroup.allfills&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;patid&lt;/TD&gt;&lt;TD&gt;fill_dt&lt;/TD&gt;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nbsp;&lt;/P&gt;&lt;P&gt;For patid 100100, this person currently has 20 observations in nif2, with each fill_dt repeating 4 times. I need the individual to retain the original number of observations from 'nif1' when creating 'nif2', with only the creation of amlinwash added to the new dataset (as shown in table).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my data, each fill_dt has a unique 'fill ID'; if I take the first unique value of the fill ID within each unique patid, I should get what I need.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2023 17:11:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-update-not-working-updating-a-dataset-based-on-dates-in/m-p/895724#M353900</guid>
      <dc:creator>dominiquec</dc:creator>
      <dc:date>2023-09-25T17:11:03Z</dc:date>
    </item>
  </channel>
</rss>

