<?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 values in a set of variables if they appear before or after an index date in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Update-values-in-a-set-of-variables-if-they-appear-before-or/m-p/930555#M41846</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB;
  input ID :$20. Admission :date9. Discharge :date9. Index  Morbidity1  Morbidity2  Morbidity3  Morbidity4;
  format Admission  Discharge date9.;
cards;
0001  13JAN2017 25JAN2017   1     1    0     1    0
0001  13JAN2017 25JAN2017   1     1    0     1    0
0001  22FEB2017 03MAR2017   0     0    1     0    0
0001  30JAN2019 04MAR2019   0     1    0     0    0
0002  01DEC2018 14DEC2018   0     1    0     1    0
0002  25DEC2018 02JAN2019   1     0    0     1    0
0002  25NOV2020 03DEC2020   0     1    1     1    1
0003  09JAN2016 25JAN2016   1     0    0     1    0
0003  29JAN2018 12FEB2018   0     0    0     1    1
;
data want;
do i=1 by 1 until(last.id);
 set DB;
 by ID;
 if Index=1 then _i=i;
end;
do i=1 by 1 until(last.id);
 set DB;
 by ID;
 if _i&amp;lt;i and not missing(_i) then do;Morbidity1=0;  Morbidity2=0; Morbidity3=0;  Morbidity4=0;  end;
 output;
end;
drop i _i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 02 Jun 2024 01:13:04 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2024-06-02T01:13:04Z</dc:date>
    <item>
      <title>Update values in a set of variables if they appear before or after an index date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Update-values-in-a-set-of-variables-if-they-appear-before-or/m-p/930522#M41845</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;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB;
  input ID :$20. Admission :date09. Discharge :date09. Index  Morbidity1  Morbidity2  Morbidity3  Morbidity4;
cards;
0001  13JAN2017 25JAN2017   1     1    0     1    0
0001  13JAN2017 25JAN2017   1     1    0     1    0
0001  22FEB2017 03MAR2017   0     0    1     0    0
0001  30JAN2019 04MAR2019   0     1    0     0    0
0002  01DEC2018 14DEC2018   0     1    0     1    0
0002  25DEC2018 02JAN2019   1     0    0     1    0
0002  25NOV2020 03DEC2020   0     1    1     1    1
0003  09JAN2016 25JAN2016   1     0    0     1    0
0003  29JAN2018 12FEB2018   0     0    0     1    1
...;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is there a way to get the following?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB1;
  input ID :$20. Admission :date09. Discharge :date09. Index  Morbidity1  Morbidity2  Morbidity3  Morbidity4;
cards;
0001  13JAN2017 25JAN2017   1     1    0     1    0
0001  13JAN2017 25JAN2017   1     1    0     1    0
0001  22FEB2017 03MAR2017   0     0    0     0    0
0001  30JAN2019 04MAR2019   0     0    0     0    0
0002  01DEC2018 14DEC2018   0     1    0     1    0
0002  25DEC2018 02JAN2019   1     0    0     1    0
0002  25NOV2020 03DEC2020   0     0    0     0    0
0003  09JAN2016 25JAN2016   1     0    0     1    0
0003  29JAN2018 12FEB2018   0     0    0     0    0
...;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In other words if morbidity* occurs before or at Index = 1 then nothing happens, otherwise if Morbidity* happens after Index = 1 (meaning after the date where Index = 1) all values in Morbidity* columns should be set = 0. So, all "1s" will become 0.&lt;/P&gt;
&lt;P&gt;Note that each patient has only one chance that Index = 1. In the reported example, pts 0001 has 2 records where Index = 1 but the date is the same. This could happen. Replicated rows are present because there are other variables not shown here. Finally, Morbidities* are 20 variables with specific name. Here Morbidity is reported for simplicity. I can customize column names in my data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much for your help.&lt;/P&gt;</description>
      <pubDate>Sat, 01 Jun 2024 14:15:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Update-values-in-a-set-of-variables-if-they-appear-before-or/m-p/930522#M41845</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2024-06-01T14:15:42Z</dc:date>
    </item>
    <item>
      <title>Re: Update values in a set of variables if they appear before or after an index date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Update-values-in-a-set-of-variables-if-they-appear-before-or/m-p/930555#M41846</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB;
  input ID :$20. Admission :date9. Discharge :date9. Index  Morbidity1  Morbidity2  Morbidity3  Morbidity4;
  format Admission  Discharge date9.;
cards;
0001  13JAN2017 25JAN2017   1     1    0     1    0
0001  13JAN2017 25JAN2017   1     1    0     1    0
0001  22FEB2017 03MAR2017   0     0    1     0    0
0001  30JAN2019 04MAR2019   0     1    0     0    0
0002  01DEC2018 14DEC2018   0     1    0     1    0
0002  25DEC2018 02JAN2019   1     0    0     1    0
0002  25NOV2020 03DEC2020   0     1    1     1    1
0003  09JAN2016 25JAN2016   1     0    0     1    0
0003  29JAN2018 12FEB2018   0     0    0     1    1
;
data want;
do i=1 by 1 until(last.id);
 set DB;
 by ID;
 if Index=1 then _i=i;
end;
do i=1 by 1 until(last.id);
 set DB;
 by ID;
 if _i&amp;lt;i and not missing(_i) then do;Morbidity1=0;  Morbidity2=0; Morbidity3=0;  Morbidity4=0;  end;
 output;
end;
drop i _i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 02 Jun 2024 01:13:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Update-values-in-a-set-of-variables-if-they-appear-before-or/m-p/930555#M41846</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-06-02T01:13:04Z</dc:date>
    </item>
    <item>
      <title>Re: Update values in a set of variables if they appear before or after an index date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Update-values-in-a-set-of-variables-if-they-appear-before-or/m-p/930561#M41847</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set db;
by id admission; * admission to guarantee order by date;
array mo {*} morb:;
retain _index;
if first.id then _index = 0;
if index then _index = 1;
if _index
then do _i = 1 to dim(mo);
  mo{_i} = 0;
end;
drop _i _index;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 02 Jun 2024 06:55:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Update-values-in-a-set-of-variables-if-they-appear-before-or/m-p/930561#M41847</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-06-02T06:55:02Z</dc:date>
    </item>
  </channel>
</rss>

