<?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: proc sql update statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-update-statement/m-p/230557#M41827</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just to add my two penneth, yes this isn't a good idea. &amp;nbsp;There are options, however you are better doing this in datastep, or creating a new dataset, i.e. do a join.&lt;/P&gt;</description>
    <pubDate>Mon, 19 Oct 2015 11:55:53 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2015-10-19T11:55:53Z</dc:date>
    <item>
      <title>proc sql update statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-update-statement/m-p/230552#M41824</link>
      <description>&lt;DIV class="post-text"&gt;&lt;P&gt;I have two tables, Table A has user Id and 5 different product columns(empty, to be filled by count ). Table B has timestamp user id and product id ( purchased at time timestamp ). This code id giving error&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc SQL;&lt;/P&gt;&lt;P&gt;update table_A as table_A&lt;/P&gt;&lt;P&gt;set Count_Product_1 =&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(select count(product_ID) from Table_B inner join Table_A on Table_A.User_ID=Table_B.User_ID&lt;/P&gt;&lt;P&gt;where Product_ID='Unique_identifier_product_1');&lt;/P&gt;&lt;P&gt;Quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;error: You cannot reopen Table_A for update access with member-level control because Table_A is in use by you in resource environment SQL&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 19 Oct 2015 11:30:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-update-statement/m-p/230552#M41824</guid>
      <dc:creator>piyushdwij</dc:creator>
      <dc:date>2015-10-19T11:30:16Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql update statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-update-statement/m-p/230553#M41825</link>
      <description>&lt;P&gt;Hi, morning.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can't update a table with itself. You need to create a copy of the table as done in below code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The technique Geraldo proposes would also work as long as the string of account numbers doesn't exceed 32K (the max. storage capacity of a SAS macro variable).&lt;/P&gt;
&lt;P&gt;In your case with Account_Num of length 10 plus 2 quotes and a comma per account number you could maximally store 2520 distinct values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data EMB2;
  infile datalines dsd dlm=',';
  input Account_Num:$10. As_of_Dt:date9. Account_Status $; 
  format As_of_Dt date9.;
  retain New_Downgrade_Flag ' ';
datalines;
S77856455E,31Jan2011,Passed
TX2342331F,31Jan2011,Passed
S77856455E,28Feb2011,Passed
TX2342331F,28Feb2011,Loss
;
run;
PROC SQL;
  create table EMB2_int as
    SELECT ACCOUNT_NUM FROM EMB2
    WHERE ACCOUNT_STATUS IN ('Passed', 'Special Mention (Tech)', 'Special Mention')
          AND AS_OF_DT = '31JAN2011'D
  ;
  UPDATE EMB2 AS U
    SET NEW_DOWNGRADE_FLAG = '1' 
    where 
          U.ACCOUNT_STATUS IN ('Doubtful', 'Sub-Standard', 'Loss')
      AND U.AS_OF_DT = '28FEB2011'D
      AND U.ACCOUNT_NUM in (select I.ACCOUNT_NUM from EMB2_int I)
  ;
  drop table EMB2_int
  ;
quit;
proc print data=EMB2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Check these links : &amp;nbsp;&lt;A title="PROC SQL - UPDATE" href="https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-Update-table-from-same-table/td-p/26208" target="_blank"&gt;PROC SQL - UPDATE&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;A title="PROC SQL UPDATE PROBLEM" href="https://communities.sas.com/t5/Base-SAS-Programming/Problem-with-PROC-SQL-UPDATE/m-p/225835#U225835" target="_blank"&gt;PROC SQL UPDATE PROBLEM&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is another question about the same metter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this might help you Mate &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2015 11:43:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-update-statement/m-p/230553#M41825</guid>
      <dc:creator>DartRodrigo</dc:creator>
      <dc:date>2015-10-19T11:43:57Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql update statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-update-statement/m-p/230556#M41826</link>
      <description>&lt;P&gt;By using de-normalised table structure, you are making life harder.&amp;nbsp;What happens when you decide to count 7 products, and so forth? Wide table&amp;nbsp;format should only be used in report output and data mining analytic tables.&lt;/P&gt;&lt;P&gt;Transpose the target table design ("A") by using a&amp;nbsp;combined key with ID and Product. Then you should be able to&amp;nbsp;calculate this in one execution. Or if you like, still by product, but just using append/insert into syntax.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2015 11:50:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-update-statement/m-p/230556#M41826</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2015-10-19T11:50:39Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql update statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-update-statement/m-p/230557#M41827</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just to add my two penneth, yes this isn't a good idea. &amp;nbsp;There are options, however you are better doing this in datastep, or creating a new dataset, i.e. do a join.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2015 11:55:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-update-statement/m-p/230557#M41827</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-10-19T11:55:53Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql update statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-update-statement/m-p/230562#M41828</link>
      <description>&lt;P&gt;thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2015 12:09:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-update-statement/m-p/230562#M41828</guid>
      <dc:creator>piyushdwij</dc:creator>
      <dc:date>2015-10-19T12:09:04Z</dc:date>
    </item>
  </channel>
</rss>

