<?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 proc sql update in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/proc-sql-update/m-p/555275#M9649</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a simple question:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data table 1;&lt;BR /&gt;input id A B C;&lt;BR /&gt;cards;&lt;BR /&gt;1 2 3 4&lt;BR /&gt;2 5 5 5&lt;BR /&gt;3 7 6 5&lt;BR /&gt;4 9 6 1&lt;BR /&gt;5 5 7 2&lt;BR /&gt;6 7 8 1&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data&amp;nbsp;table 2 ;&lt;BR /&gt;input id A B C;&lt;BR /&gt;cards;&lt;BR /&gt;1 2 3 4&lt;BR /&gt;1 4 2 5&lt;BR /&gt;1 5 3 12&lt;BR /&gt;1 7 34 3&lt;BR /&gt;2 5 5 5&lt;BR /&gt;2 6 12 0&lt;BR /&gt;2 9 3 2&lt;BR /&gt;2 11 3 1&lt;BR /&gt;3 7 6 5&lt;BR /&gt;3 23 3 2&lt;BR /&gt;3 12 12 44&lt;BR /&gt;4 4 23 33&lt;BR /&gt;4 9 6 1&lt;BR /&gt;5 5 7 2&lt;BR /&gt;6 7 8 1&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to update&amp;nbsp; variable B in Table 1 where the id in two tables are the same (first condition) and A is at maximum in table 2.&lt;/P&gt;&lt;P&gt;Because for some id( say 1, 2) in table 2&amp;nbsp; I have several rows.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, it will be the updated table:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data table 1;&lt;BR /&gt;input id A B C;&lt;BR /&gt;cards;&lt;BR /&gt;1 2 34 4&lt;BR /&gt;2 5 3 5&lt;BR /&gt;3 7 3 5&lt;BR /&gt;4 9 6 1&lt;BR /&gt;5 5 7 2&lt;BR /&gt;6 7 8 1&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc SQL;&lt;BR /&gt;update table 1 set B= (select B from table 2 where table 1.id=table 2.id&amp;nbsp; and table 2.A=max); quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know the above code, after the and is not correct!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Wed, 01 May 2019 04:59:24 GMT</pubDate>
    <dc:creator>ali_far</dc:creator>
    <dc:date>2019-05-01T04:59:24Z</dc:date>
    <item>
      <title>proc sql update</title>
      <link>https://communities.sas.com/t5/New-SAS-User/proc-sql-update/m-p/555275#M9649</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a simple question:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data table 1;&lt;BR /&gt;input id A B C;&lt;BR /&gt;cards;&lt;BR /&gt;1 2 3 4&lt;BR /&gt;2 5 5 5&lt;BR /&gt;3 7 6 5&lt;BR /&gt;4 9 6 1&lt;BR /&gt;5 5 7 2&lt;BR /&gt;6 7 8 1&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data&amp;nbsp;table 2 ;&lt;BR /&gt;input id A B C;&lt;BR /&gt;cards;&lt;BR /&gt;1 2 3 4&lt;BR /&gt;1 4 2 5&lt;BR /&gt;1 5 3 12&lt;BR /&gt;1 7 34 3&lt;BR /&gt;2 5 5 5&lt;BR /&gt;2 6 12 0&lt;BR /&gt;2 9 3 2&lt;BR /&gt;2 11 3 1&lt;BR /&gt;3 7 6 5&lt;BR /&gt;3 23 3 2&lt;BR /&gt;3 12 12 44&lt;BR /&gt;4 4 23 33&lt;BR /&gt;4 9 6 1&lt;BR /&gt;5 5 7 2&lt;BR /&gt;6 7 8 1&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to update&amp;nbsp; variable B in Table 1 where the id in two tables are the same (first condition) and A is at maximum in table 2.&lt;/P&gt;&lt;P&gt;Because for some id( say 1, 2) in table 2&amp;nbsp; I have several rows.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, it will be the updated table:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data table 1;&lt;BR /&gt;input id A B C;&lt;BR /&gt;cards;&lt;BR /&gt;1 2 34 4&lt;BR /&gt;2 5 3 5&lt;BR /&gt;3 7 3 5&lt;BR /&gt;4 9 6 1&lt;BR /&gt;5 5 7 2&lt;BR /&gt;6 7 8 1&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc SQL;&lt;BR /&gt;update table 1 set B= (select B from table 2 where table 1.id=table 2.id&amp;nbsp; and table 2.A=max); quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know the above code, after the and is not correct!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 01 May 2019 04:59:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/proc-sql-update/m-p/555275#M9649</guid>
      <dc:creator>ali_far</dc:creator>
      <dc:date>2019-05-01T04:59:24Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql update</title>
      <link>https://communities.sas.com/t5/New-SAS-User/proc-sql-update/m-p/555291#M9650</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/149294"&gt;@ali_far&lt;/a&gt;,&amp;nbsp;please do not double post &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See my answer in your related thread &lt;A href="https://communities.sas.com/t5/SAS-Programming/proc-sql-update/m-p/555285/highlight/false#M154525" target="_self"&gt;here&lt;/A&gt;&amp;nbsp;and let me know if it works for you&lt;/P&gt;</description>
      <pubDate>Wed, 01 May 2019 07:19:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/proc-sql-update/m-p/555291#M9650</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-05-01T07:19:02Z</dc:date>
    </item>
  </channel>
</rss>

