<?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: Modify variable values based on condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Modify-variable-values-based-on-condition/m-p/474636#M121966</link>
    <description>&lt;P&gt;I think this captures it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
do until(last.subject);
    set have; by subject;
    if days &amp;lt;= 0 then maxNeg = max(maxNeg, days);   
    end;
do until(last.subject);
    set have; by subject;
    if days = maxNeg then days = 0;
    if days &amp;gt;= 0 then output;
    end;
drop maxNeg;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 30 Jun 2018 05:21:39 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2018-06-30T05:21:39Z</dc:date>
    <item>
      <title>Modify variable values based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Modify-variable-values-based-on-condition/m-p/474633#M121964</link>
      <description>&lt;P&gt;I need to examine the profile of each&amp;nbsp;patient, but it is little complicated for a novice programmer like me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If it is more than one negative DAYS,then I need to eliminate all of them except that nearest the origin(in below example record of -5 will be eliminated and -1 becomes 0). If there is an observation with days = 0&amp;nbsp;then all negative days can be eliminated. If there is no observation with DAYS=0 then change the negative DAYS to DAYS=0. Please note that in the exceptional case where there is only one DAYS for a patient then it is retained even if DAYS is&amp;nbsp;negative (it will of course be changed to 0)&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;&lt;PRE&gt;data have;

   input subject days grade;

datalines;

12345  -5      0    /*deleted*/

12345   -1     0    /* -1 becomes 0*/

12345    12   1

12345    15   1

12345    21   1

12345   30    2

12345   35    2

23456    -3    0    /*deleted*/

23456    -5    0    /*deleted*/

23456     0    0   

23456     9    1

23456    13   1

34567   -5    0     /* -5 becomes 0 */
34567    8    1
34567    16   1
45678    -2   0     /* -2 becomes 0 */

run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I need the output to look like below,&lt;/P&gt;&lt;P&gt;&amp;nbsp;subject&amp;nbsp; &amp;nbsp; days&amp;nbsp; &amp;nbsp;grade&lt;/P&gt;&lt;P&gt;12345&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;12345&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;12345&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;15&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;12345&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;21&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;12345&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;30&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;12345&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;35&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;23456&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;23456&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;23456&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 13&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;34567&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;34567&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;8&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;34567&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;16&amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;45678&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp;&amp;nbsp; &amp;nbsp;0&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would greatly appreciate any suggestions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 30 Jun 2018 04:44:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Modify-variable-values-based-on-condition/m-p/474633#M121964</guid>
      <dc:creator>gpv2000</dc:creator>
      <dc:date>2018-06-30T04:44:01Z</dc:date>
    </item>
    <item>
      <title>Re: Modify variable values based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Modify-variable-values-based-on-condition/m-p/474636#M121966</link>
      <description>&lt;P&gt;I think this captures it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
do until(last.subject);
    set have; by subject;
    if days &amp;lt;= 0 then maxNeg = max(maxNeg, days);   
    end;
do until(last.subject);
    set have; by subject;
    if days = maxNeg then days = 0;
    if days &amp;gt;= 0 then output;
    end;
drop maxNeg;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 30 Jun 2018 05:21:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Modify-variable-values-based-on-condition/m-p/474636#M121966</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-06-30T05:21:39Z</dc:date>
    </item>
    <item>
      <title>Re: Modify variable values based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Modify-variable-values-based-on-condition/m-p/474678#M121985</link>
      <description>Yes it worked. Thank you very much. I am still learning to use do until . Your code did it quickly and neatly. Thanks.</description>
      <pubDate>Sat, 30 Jun 2018 15:46:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Modify-variable-values-based-on-condition/m-p/474678#M121985</guid>
      <dc:creator>gpv2000</dc:creator>
      <dc:date>2018-06-30T15:46:38Z</dc:date>
    </item>
  </channel>
</rss>

