<?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: Update all records corresponding to the same ID with the value of a variable in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Update-all-records-corresponding-to-the-same-ID-with-the-value/m-p/930365#M41833</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB;
input ID :$20. Discharge :date9. Discharge_n :date9.;
format Discharge :date9. Discharge_n :date9.;
cards;
0001 13FEB2019 .
0001 01FEB2019 28FEB2019
0002 01FEB2020 .
0002 04FEB2020 28FEB2020
;
data want;
do until(last.id);
 set DB;
 by id;
 if last.id and discharge_n &amp;gt; discharge then do;flag=1;temp=Discharge_n;end;
end;
do until(last.id);
 set DB;
 by id;
 if flag then do;
   if not missing(Discharge) then Discharge=temp;
   if not missing(Discharge_n) then Discharge_n=temp;
   output;
 end;
end;
drop flag temp;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 31 May 2024 03:28:53 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2024-05-31T03:28:53Z</dc:date>
    <item>
      <title>Update all records corresponding to the same ID with the value of a variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Update-all-records-corresponding-to-the-same-ID-with-the-value/m-p/930274#M41828</link>
      <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose to have the following:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data DB;&lt;BR /&gt;input ID :$20. Discharge :date9. Discharge_n :date9.;&lt;BR /&gt;format Discharge :date9. Discharge_n :date9.;&lt;BR /&gt;cards;&lt;BR /&gt;0001 13FEB2019 .&lt;BR /&gt;0001 01FEB2019 28FEB2019&lt;BR /&gt;0002 01FEB2020 .&lt;BR /&gt;0002 04FEB2020 28FEB2020&lt;BR /&gt;;&lt;/PRE&gt;
&lt;P&gt;then you want to update Discharge (all the fields, missings and not) with the variable Discharge_n to get:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB1;
  input ID :$20. Discharge :date9. Discharge_n :date9.;
  format Discharge date9. Discharge_n :date9.;
cards;
0001 28FEB2019     .      
0001 28FEB2019  28FEB2019
0002 28FEB2020     .
0002 28FEB2020  28FEB2020
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If I use the rule: if discharge_n &amp;gt; discharge only the corresponding row will be updated but I would like to update all rows corresponding to the same ID.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone help me please?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 May 2024 13:53:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Update-all-records-corresponding-to-the-same-ID-with-the-value/m-p/930274#M41828</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2024-05-30T13:53:56Z</dc:date>
    </item>
    <item>
      <title>Re: Update all records corresponding to the same ID with the value of a variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Update-all-records-corresponding-to-the-same-ID-with-the-value/m-p/930284#M41829</link>
      <description>&lt;P&gt;One way:&lt;/P&gt;
&lt;PRE&gt;data dd;
input ID :$20. DD :date9.   ;
datalines;
0001 28FEB2019
0002 28FEB2020
;

data want;
   merge db dd (In=InDD);
   by id;
   if indd then do;
      if not missing (discharge) then discharge=dd;
      if not missing (discharge_n) then discharge_n=dd;
   end;
   drop dd;
run;&lt;/PRE&gt;
&lt;P&gt;The question is where the knowledge of which ID and which date to update the values with may come from as that was not stated anywhere that I could see.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I provided a different ID to show that a subset of ID's can be addressed this way.&lt;/P&gt;</description>
      <pubDate>Thu, 30 May 2024 14:43:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Update-all-records-corresponding-to-the-same-ID-with-the-value/m-p/930284#M41829</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-05-30T14:43:09Z</dc:date>
    </item>
    <item>
      <title>Re: Update all records corresponding to the same ID with the value of a variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Update-all-records-corresponding-to-the-same-ID-with-the-value/m-p/930365#M41833</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB;
input ID :$20. Discharge :date9. Discharge_n :date9.;
format Discharge :date9. Discharge_n :date9.;
cards;
0001 13FEB2019 .
0001 01FEB2019 28FEB2019
0002 01FEB2020 .
0002 04FEB2020 28FEB2020
;
data want;
do until(last.id);
 set DB;
 by id;
 if last.id and discharge_n &amp;gt; discharge then do;flag=1;temp=Discharge_n;end;
end;
do until(last.id);
 set DB;
 by id;
 if flag then do;
   if not missing(Discharge) then Discharge=temp;
   if not missing(Discharge_n) then Discharge_n=temp;
   output;
 end;
end;
drop flag temp;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 31 May 2024 03:28:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Update-all-records-corresponding-to-the-same-ID-with-the-value/m-p/930365#M41833</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-05-31T03:28:53Z</dc:date>
    </item>
  </channel>
</rss>

