<?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: Change data based on a row with same id in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Change-data-based-on-a-row-with-same-id/m-p/785942#M250882</link>
    <description>&lt;P&gt;Using a hash-object:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;

   if _n_ = 1 then do;
      declare hash h(dataset: 'work.have(where= (changed = 1))');
      h.defineKey('customer_id');
      h.defineData('changed');
      h.defineDone();
   end;

   rc = h.find();
   drop rc;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 14 Dec 2021 08:13:11 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2021-12-14T08:13:11Z</dc:date>
    <item>
      <title>Change data based on a row with same id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-data-based-on-a-row-with-same-id/m-p/785829#M250840</link>
      <description>&lt;P&gt;I have some data that I pulled for current year orders in a database. The variable changed indicates if they had sensitive information changed in that year. I want to modify the previous entries, or any entries going forward to have changed = 1 if the customer_id is the same and changed = 1 at any entry of that customer_id. If a customer_id doesnt have changed = 1 on any row then I want to leave it alone.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here is a small subset of one customer id as an example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;DATA have;
input order_num customer_id changed
DATALINES;
412 067 0
623 067 0
871 067 1&lt;BR /&gt;942 067 0&lt;BR /&gt;512&amp;nbsp;098&amp;nbsp;0&lt;BR /&gt;662&amp;nbsp;098&amp;nbsp;0&lt;BR /&gt;112&amp;nbsp;023&amp;nbsp;0&lt;BR /&gt;987&amp;nbsp;023&amp;nbsp;1&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In this example I'm trying to have customer_id 067 and 023 have changed = 1 for all rows while leaving customer id 098 alone.&lt;/P&gt;&lt;P&gt;like so:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;DATA have;
input order_num customer_id changed
DATALINES;
412 067 1
623 067 1
871 067 1&lt;BR /&gt;&lt;CODE class=""&gt;942 067 1&lt;BR /&gt;512&amp;nbsp;098&amp;nbsp;0&lt;BR /&gt;662&amp;nbsp;098&amp;nbsp;0&lt;BR /&gt;112&amp;nbsp;023&amp;nbsp;1&lt;BR /&gt;987&amp;nbsp;023&amp;nbsp;1&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I'm not sure how this can be done so any help would be appreciated. Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 13 Dec 2021 18:26:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-data-based-on-a-row-with-same-id/m-p/785829#M250840</guid>
      <dc:creator>raddad34</dc:creator>
      <dc:date>2021-12-13T18:26:05Z</dc:date>
    </item>
    <item>
      <title>Re: Change data based on a row with same id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-data-based-on-a-row-with-same-id/m-p/785833#M250842</link>
      <description>&lt;P&gt;Please provide a larger example that includes more individuals and cases where you would not change the data otherwise any solution is unlikely to work with your actual data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/391589"&gt;@raddad34&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have some data that I pulled for current year orders in a database. The variable changed indicates if they had sensitive information changed in that year. I want to modify the previous entries, or any entries going forward to have changed = 1 if the customer_id is the same and changed = 1 at any entry of that customer_id. If a customer_id doesnt have changed = 1 on any row then I want to leave it alone.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;here is a small subset of one customer id as an example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;DATA have;
input order_num customer_id changed
DATALINES;
412 067 0
623 067 0
871 067 1&lt;BR /&gt;942 067 0&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and I want&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;DATA have;
input order_num customer_id changed
DATALINES;
412 067 1
623 067 1
871 067 1&lt;BR /&gt;&lt;CODE class=""&gt;942 067 1&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I'm not sure how this can be done so any help would be appreciated. Thanks&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Dec 2021 18:21:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-data-based-on-a-row-with-same-id/m-p/785833#M250842</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-13T18:21:13Z</dc:date>
    </item>
    <item>
      <title>Re: Change data based on a row with same id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-data-based-on-a-row-with-same-id/m-p/785840#M250845</link>
      <description>Sorry about that! I've added more cases in my original post. thanks.</description>
      <pubDate>Mon, 13 Dec 2021 18:26:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-data-based-on-a-row-with-same-id/m-p/785840#M250845</guid>
      <dc:creator>raddad34</dc:creator>
      <dc:date>2021-12-13T18:26:49Z</dc:date>
    </item>
    <item>
      <title>Re: Change data based on a row with same id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-data-based-on-a-row-with-same-id/m-p/785869#M250856</link>
      <description>&lt;P&gt;SQL option:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as 
select *, max(changed) as want_changed
from have
group by customer_id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Data Step Option:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by customer_id descending changed;
run;

data want;
set have;
by customer_ID descending changed;

retain want_changed;

if first.customer_ID then want_changed = changed;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/391589"&gt;@raddad34&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have some data that I pulled for current year orders in a database. The variable changed indicates if they had sensitive information changed in that year. I want to modify the previous entries, or any entries going forward to have changed = 1 if the customer_id is the same and changed = 1 at any entry of that customer_id. If a customer_id doesnt have changed = 1 on any row then I want to leave it alone.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;here is a small subset of one customer id as an example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;DATA have;
input order_num customer_id changed
DATALINES;
412 067 0
623 067 0
871 067 1&lt;BR /&gt;942 067 0&lt;BR /&gt;512&amp;nbsp;098&amp;nbsp;0&lt;BR /&gt;662&amp;nbsp;098&amp;nbsp;0&lt;BR /&gt;112&amp;nbsp;023&amp;nbsp;0&lt;BR /&gt;987&amp;nbsp;023&amp;nbsp;1&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In this example I'm trying to have customer_id 067 and 023 have changed = 1 for all rows while leaving customer id 098 alone.&lt;/P&gt;
&lt;P&gt;like so:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;DATA have;
input order_num customer_id changed
DATALINES;
412 067 1
623 067 1
871 067 1&lt;BR /&gt;&lt;CODE class=""&gt;942 067 1&lt;BR /&gt;512&amp;nbsp;098&amp;nbsp;0&lt;BR /&gt;662&amp;nbsp;098&amp;nbsp;0&lt;BR /&gt;112&amp;nbsp;023&amp;nbsp;1&lt;BR /&gt;987&amp;nbsp;023&amp;nbsp;1&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I'm not sure how this can be done so any help would be appreciated. Thanks&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Dec 2021 20:28:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-data-based-on-a-row-with-same-id/m-p/785869#M250856</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-13T20:28:56Z</dc:date>
    </item>
    <item>
      <title>Re: Change data based on a row with same id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-data-based-on-a-row-with-same-id/m-p/785942#M250882</link>
      <description>&lt;P&gt;Using a hash-object:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;

   if _n_ = 1 then do;
      declare hash h(dataset: 'work.have(where= (changed = 1))');
      h.defineKey('customer_id');
      h.defineData('changed');
      h.defineDone();
   end;

   rc = h.find();
   drop rc;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Dec 2021 08:13:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-data-based-on-a-row-with-same-id/m-p/785942#M250882</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-12-14T08:13:11Z</dc:date>
    </item>
    <item>
      <title>Re: Change data based on a row with same id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-data-based-on-a-row-with-same-id/m-p/786019#M250899</link>
      <description>Thank you for the replies everyone! I really appreciate it!</description>
      <pubDate>Tue, 14 Dec 2021 16:18:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-data-based-on-a-row-with-same-id/m-p/786019#M250899</guid>
      <dc:creator>raddad34</dc:creator>
      <dc:date>2021-12-14T16:18:02Z</dc:date>
    </item>
  </channel>
</rss>

