<?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: Conditional replacement of a variable values in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Conditional-replacement-of-a-variable-values/m-p/951705#M42768</link>
    <description>&lt;P&gt;So you want to set INDEX to the minimum value of INDEX for each ID?&lt;/P&gt;
&lt;P&gt;In PROC SQL you could do that like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table db1 as
  select id,admission,discharge,min(index) as Index
  from db
  group by id
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That works because PROC SQL will remerge the aggregate value back onto the detail observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or you could calculate the minimum and then do the remerge.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=db ;
  by id;
  var index ;
  output out=summary(keep=id index) min= ;
run;
data db1;
  merge db summary;
  by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 23 Nov 2024 17:41:27 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-11-23T17:41:27Z</dc:date>
    <item>
      <title>Conditional replacement of a variable values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditional-replacement-of-a-variable-values/m-p/951704#M42767</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;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB;
  input ID :$20. Admission :date09. Discharge :date09. Index; 
  format Admission date9. Discharge date9.;
cards;
0001 13JAN2015 20JAN2015 1
0001 21FEB2015 31DEC2015 0
0001 01MAR2018 30SEP2018 0
0001 01JAN2019 31DEC2019 0
0002 01JAN2015 31DEC2015 0
0002 01JAN2019 31OCT2019 0
0003 08FEB2014 10MAR2014 1
0003 16JUN2015 13JUL2015 0
0004 04MAY2016 10MAY2016 1
0004 13SEP2017 15NOV2017 1
0004 09DEC2018 31DEC2018 0
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to get the following?&amp;nbsp;&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; 
  format Admission date9. Discharge date9.;
cards;
0001 13JAN2015 20JAN2015 0
0001 21FEB2015 31DEC2015 0
0001 01MAR2018 30SEP2018 0
0001 01JAN2019 31DEC2019 0
0002 01JAN2015 31DEC2015 0
0002 01JAN2019 31OCT2019 0
0003 08FEB2014 10MAR2014 0
0003 16JUN2015 13JUL2015 0
0004 04MAY2016 10MAY2016 0
0004 13SEP2017 15NOV2017 0
0004 09DEC2018 31DEC2018 0
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In other words, for each patient, if there is at least one 0&amp;nbsp; in the column Index (doesn't matter the date) then Index = 1 should be converted to Index = 0.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Nov 2024 16:41:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditional-replacement-of-a-variable-values/m-p/951704#M42767</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2024-11-23T16:41:58Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional replacement of a variable values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditional-replacement-of-a-variable-values/m-p/951705#M42768</link>
      <description>&lt;P&gt;So you want to set INDEX to the minimum value of INDEX for each ID?&lt;/P&gt;
&lt;P&gt;In PROC SQL you could do that like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table db1 as
  select id,admission,discharge,min(index) as Index
  from db
  group by id
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That works because PROC SQL will remerge the aggregate value back onto the detail observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or you could calculate the minimum and then do the remerge.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=db ;
  by id;
  var index ;
  output out=summary(keep=id index) min= ;
run;
data db1;
  merge db summary;
  by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 23 Nov 2024 17:41:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditional-replacement-of-a-variable-values/m-p/951705#M42768</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-11-23T17:41:27Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional replacement of a variable values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditional-replacement-of-a-variable-values/m-p/951706#M42769</link>
      <description>Thank you very much Tom for your help. Yes, basically I would like to set Index at minimum.</description>
      <pubDate>Sat, 23 Nov 2024 17:50:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditional-replacement-of-a-variable-values/m-p/951706#M42769</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2024-11-23T17:50:05Z</dc:date>
    </item>
  </channel>
</rss>

