<?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: using modify with duplicate key values in master data set and transaction data set in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/using-modify-with-duplicate-key-values-in-master-data-set-and/m-p/326502#M72718</link>
    <description>&lt;P&gt;Thank you! i am wondering that why it used the 'dummy variable' &amp;nbsp;and as for the hash table.i will try to program with it.&lt;/P&gt;</description>
    <pubDate>Sat, 21 Jan 2017 14:14:56 GMT</pubDate>
    <dc:creator>JNWong</dc:creator>
    <dc:date>2017-01-21T14:14:56Z</dc:date>
    <item>
      <title>using modify with duplicate key values in master data set and transaction data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-modify-with-duplicate-key-values-in-master-data-set-and/m-p/326497#M72715</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;As my data set like: I get the code,but I cannot understand it and i want to know if there exists other methods. Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data master(index=(ssn));
input ssn: $11. nickname $;
datalines;
161-60-5881 joshua
161-60-5881 joshua
160-58-1223 kathryn
160-58-1223 kathryn
134-56-9094 megan
;
data trans;
input ssn : $11. nickname $;
datalines;
161-60-5881 josh
160-58-1223 kathy
160-58-1223 kate
134-56-9094 meg
142-67-9888 bill
;&lt;BR /&gt;&lt;BR /&gt;proc sort data = trans;&lt;BR /&gt;by ssn;&lt;BR /&gt;data master;&lt;BR /&gt;set trans;&lt;BR /&gt;by ssn;&lt;BR /&gt;dummy = 0;&lt;BR /&gt;do until (_iorc_=%sysrc(_dsenom));&lt;BR /&gt;if dummy then ssn = '999-99-9999';&lt;BR /&gt;modify master key = ssn;&lt;BR /&gt;select(_iorc_);&lt;BR /&gt;when (%sysrc(_sok)) do;&lt;BR /&gt;nickname = tnickname;&lt;BR /&gt;replace master;&lt;BR /&gt;end;&lt;BR /&gt;when (%sysrc(_dsenom)) do;&lt;BR /&gt;_error_=0;&lt;BR /&gt;if not last.ssn and not dummmy then do;&lt;BR /&gt;dummy = 1;&lt;BR /&gt;_iorc_=0;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;otherwise;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Jan 2017 12:59:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-modify-with-duplicate-key-values-in-master-data-set-and/m-p/326497#M72715</guid>
      <dc:creator>JNWong</dc:creator>
      <dc:date>2017-01-21T12:59:47Z</dc:date>
    </item>
    <item>
      <title>Re: using modify with duplicate key values in master data set and transaction data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-modify-with-duplicate-key-values-in-master-data-set-and/m-p/326501#M72717</link>
      <description>&lt;P&gt;It is in the nature of the MODIFY statement with KEY= to retrieve the rows from the master in order of the index, starting with the first row. If you repeatedly retrieve rows with the same KEY lookup value until the last record is found. At that moment&amp;nbsp; the macro %SYSRC yields a &amp;amp;_DSENOM signalling a non-match. Note that the MODIFY statement actually retrieves rows much like SET and does not in itself updates in the specified table. Other than that please make clear what you do not understand so we can address that mor eeffectively.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An alternative is to use SQL using UPDATE with a SELECT subquery:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;

update master

set nickname=(select nickname from trans where mastern.nickname=trans.nickname)

;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Other advanced methods exist like using a hastable. I leave that as homework.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;lt;soapbox&amp;gt;In general ( I know we're looking an example from the SAS docs) I object to master tables with duplicate keys. They can occur but only when also a primary (unique) key exists.&amp;lt;/soapbox&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;-- Jan&lt;/P&gt;</description>
      <pubDate>Sat, 21 Jan 2017 13:53:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-modify-with-duplicate-key-values-in-master-data-set-and/m-p/326501#M72717</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2017-01-21T13:53:15Z</dc:date>
    </item>
    <item>
      <title>Re: using modify with duplicate key values in master data set and transaction data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-modify-with-duplicate-key-values-in-master-data-set-and/m-p/326502#M72718</link>
      <description>&lt;P&gt;Thank you! i am wondering that why it used the 'dummy variable' &amp;nbsp;and as for the hash table.i will try to program with it.&lt;/P&gt;</description>
      <pubDate>Sat, 21 Jan 2017 14:14:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-modify-with-duplicate-key-values-in-master-data-set-and/m-p/326502#M72718</guid>
      <dc:creator>JNWong</dc:creator>
      <dc:date>2017-01-21T14:14:56Z</dc:date>
    </item>
  </channel>
</rss>

