<?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: How do I changes the values ​​of the records in the table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-changes-the-values-of-the-records-in-the-table/m-p/683538#M207059</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Branch_Id   Rating;
order = _n_;
cards;
1   1
1   0
1   1
2   0
2   0
2   1
4   0
4   0
4   0
5   1
5   1
5   2
;;;;

proc sort data=have;
by branch_ID rating;
run;

data want;
set have;
by branch_id rating;
original_rating = rating;
retain first_flag 0;

if first.branch_id then first_flag=0;

if first.rating and rating = 0 then first_flag = 1;
else if rating = 0 and first_flag = 1 then rating = 1;
run;

proc sort data=want;
by order;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Using first logic is one way. There's probably a way to simplify this logic but this makes it pretty clear what's happening.&lt;/P&gt;</description>
    <pubDate>Sun, 13 Sep 2020 21:25:49 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-09-13T21:25:49Z</dc:date>
    <item>
      <title>How do I changes the values ​​of the records in the table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-changes-the-values-of-the-records-in-the-table/m-p/683530#M207055</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have this table:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Branch_Id&lt;/TD&gt;&lt;TD&gt;Rating&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to go through the whole table and check that if a particular branch_id has more than one record with the number 0 in the Rating field it will replace it with 1 and will always leave a maximum of one record of the number 0 per branch.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;No matter which records are replaced by the number 1 from all records with the number 0 in the same branch, the main thing is that one record remains with the number 0 in the ranking.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;If the branch does not have a record with the number 0 as in branch 5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;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Sun, 13 Sep 2020 19:19:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-changes-the-values-of-the-records-in-the-table/m-p/683530#M207055</guid>
      <dc:creator>shlomiohana</dc:creator>
      <dc:date>2020-09-13T19:19:57Z</dc:date>
    </item>
    <item>
      <title>Re: How do I changes the values ​​of the records in the table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-changes-the-values-of-the-records-in-the-table/m-p/683538#M207059</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Branch_Id   Rating;
order = _n_;
cards;
1   1
1   0
1   1
2   0
2   0
2   1
4   0
4   0
4   0
5   1
5   1
5   2
;;;;

proc sort data=have;
by branch_ID rating;
run;

data want;
set have;
by branch_id rating;
original_rating = rating;
retain first_flag 0;

if first.branch_id then first_flag=0;

if first.rating and rating = 0 then first_flag = 1;
else if rating = 0 and first_flag = 1 then rating = 1;
run;

proc sort data=want;
by order;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Using first logic is one way. There's probably a way to simplify this logic but this makes it pretty clear what's happening.&lt;/P&gt;</description>
      <pubDate>Sun, 13 Sep 2020 21:25:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-changes-the-values-of-the-records-in-the-table/m-p/683538#M207059</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-09-13T21:25:49Z</dc:date>
    </item>
    <item>
      <title>Re: How do I changes the values ​​of the records in the table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-changes-the-values-of-the-records-in-the-table/m-p/683540#M207060</link>
      <description>&lt;P&gt;Here's a one-step method that passes through each BRANCH data twice:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   changes_needed=-1;
   do until (last.branch_id);
      set have;
      by branch_id;
      if rating=0 then changes_needed + 1;
   end;
   do until (last.branch_id);
      set have;
      by branch_id;
      if rating=0 and changes_needed &amp;gt; 0 then do;
         rating=1;
         changes_needed = changes_needed - 1;
      end;
      output;
   end;
   drop changes_needed;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The top DO loop counts how many zero values need to be changed for a BRANCH_ID.&amp;nbsp; Then the bottom DO loop rereads the same observations, makes the required changes, and outputs the observations.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 13 Sep 2020 22:25:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-changes-the-values-of-the-records-in-the-table/m-p/683540#M207060</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-09-13T22:25:42Z</dc:date>
    </item>
    <item>
      <title>Re: How do I changes the values ​​of the records in the table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-changes-the-values-of-the-records-in-the-table/m-p/683573#M207074</link>
      <description>&lt;P&gt;A quick logic:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT;
  set HAVE;
  by BRANCH_ID;
  if first.BRANCH_ID then FOUND_ZERO=0;  
  if RATING=0 then FOUND_ZERO+1;
  if FOUND_ZERO&amp;gt;1 &amp;amp; RATING=0 then RATING=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Sep 2020 06:56:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-changes-the-values-of-the-records-in-the-table/m-p/683573#M207074</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-09-14T06:56:42Z</dc:date>
    </item>
  </channel>
</rss>

