<?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: Update a variable using a substraction of two different datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Update-a-variable-using-a-substraction-of-two-different-datasets/m-p/550473#M152837</link>
    <description>&lt;PRE&gt;NPT .AliasissueID = OPS.aliasissueid and
NPT .ACCOUNTID = OPS.ACCOUNTID and
NPT .legshares &amp;gt; 0 and
OPS.ASSETMINORCLSSDESC = 'CLASS_I' and&lt;/PRE&gt;
&lt;P&gt;Since you have 3 instances with a space between NPT and a variable name in the code above you are confusing the compiler as to intent. Start by getting the basic syntax correct.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I recall correctly, SAS Proc SQL will currently only allow updating a single variable as well. So you may need to drop the update for&lt;/P&gt;
&lt;PRE&gt;LEG_1_MINUS_LEG_2_SHARES=0&lt;/PRE&gt;</description>
    <pubDate>Thu, 11 Apr 2019 23:43:13 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-04-11T23:43:13Z</dc:date>
    <item>
      <title>Update a variable using a substraction of two different datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-a-variable-using-a-substraction-of-two-different-datasets/m-p/550434#M152819</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to update a column from table a with the result of the substraction of another colum from table a minus a column from table b, under some conditions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is similar to what I have:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;Update OPS&lt;/P&gt;&lt;P&gt;set&lt;BR /&gt;LEG_2 = ((select sumofdata from OPS) - (select legshares from NPT )),&lt;BR /&gt;LEG_1_MINUS_LEG_2_SHARES=0&lt;BR /&gt;where exists&lt;BR /&gt;(select * from OPS where&lt;BR /&gt;NPT .AliasissueID = OPS.aliasissueid and&lt;BR /&gt;NPT .ACCOUNTID = OPS.ACCOUNTID and&lt;BR /&gt;NPT .legshares &amp;gt; 0 and&lt;BR /&gt;OPS.ASSETMINORCLSSDESC = 'CLASS_I' and&lt;BR /&gt;NPT .Spread= 'Yes');&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;sumofdata,&amp;nbsp;legshares&amp;nbsp; and&amp;nbsp;LEG_2&amp;nbsp; are numeric.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first two where conditions are just to do the join, and the others 3 are related to the process. I think the issue is on the substraction part, this is the error I'm getting&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: You cannot reopen WORK.NPT.DATA for update access with member-level control because&lt;BR /&gt;WORK.NPT.DATA is in use by you in resource environment SQL (2).&lt;BR /&gt;ERROR: PROC SQL could not undo this statement if an ERROR were to happen as it could not obtain exclusive access to the data set.&lt;BR /&gt;This statement will not execute as the SQL option UNDO_POLICY=REQUIRED is in effect.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm working on EG version 7.12&lt;/P&gt;</description>
      <pubDate>Thu, 11 Apr 2019 21:16:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-a-variable-using-a-substraction-of-two-different-datasets/m-p/550434#M152819</guid>
      <dc:creator>Cristiansg</dc:creator>
      <dc:date>2019-04-11T21:16:53Z</dc:date>
    </item>
    <item>
      <title>Re: Update a variable using a substraction of two different datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-a-variable-using-a-substraction-of-two-different-datasets/m-p/550436#M152820</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/270356"&gt;@Cristiansg&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to update a column from table a with the result of the substraction of another colum from table a minus a column from table b, under some conditions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is similar to what I have:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;Update OPS&lt;/P&gt;
&lt;P&gt;set&lt;BR /&gt;LEG_2 = ((select sumofdata from OPS) - (select legshares from NPT )),&lt;BR /&gt;LEG_1_MINUS_LEG_2_SHARES=0&lt;BR /&gt;where exists&lt;BR /&gt;(select * from OPS where&lt;BR /&gt;NPT .AliasissueID = OPS.aliasissueid and&lt;BR /&gt;NPT .ACCOUNTID = OPS.ACCOUNTID and&lt;BR /&gt;NPT .legshares &amp;gt; 0 and&lt;BR /&gt;OPS.ASSETMINORCLSSDESC = 'CLASS_I' and&lt;BR /&gt;NPT .Spread= 'Yes');&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;sumofdata,&amp;nbsp;legshares&amp;nbsp; and&amp;nbsp;LEG_2&amp;nbsp; are numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first two where conditions are just to do the join, and the others 3 are related to the process. I think the issue is on the substraction part, this is the error I'm getting&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="5"&gt;&lt;STRONG&gt;&lt;FONT color="#ff0000"&gt;ERROR: You cannot reopen WORK.NPT.DATA for update access with member-level control because&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="5"&gt;&lt;STRONG&gt;&lt;FONT color="#ff0000"&gt;WORK.NPT.DATA is in use by you in resource environment SQL (2).&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;ERROR: PROC SQL could not undo this statement if an ERROR were to happen as it could not obtain exclusive access to the data set.&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT color="#0000ff"&gt;This statement will not execute as the SQL option UNDO_POLICY=REQUIRED is in effect.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm working on EG version 7.12&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You have the table open. Close it before running the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also you will need to address the undo policy.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Apr 2019 21:23:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-a-variable-using-a-substraction-of-two-different-datasets/m-p/550436#M152820</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-04-11T21:23:44Z</dc:date>
    </item>
    <item>
      <title>Re: Update a variable using a substraction of two different datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-a-variable-using-a-substraction-of-two-different-datasets/m-p/550446#M152823</link>
      <description>&lt;P&gt;Hi ballardw, thanks for your quick reply, but I forgot to mention that. I already reestarted SAS and the computer, but the error is still there. My theory (not sure at all) is that the table is being used to do the substraction at the same time that is being updated, so it crashes. I was trying to move the data to a third table, but it didn't work&lt;/P&gt;</description>
      <pubDate>Thu, 11 Apr 2019 21:54:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-a-variable-using-a-substraction-of-two-different-datasets/m-p/550446#M152823</guid>
      <dc:creator>Cristiansg</dc:creator>
      <dc:date>2019-04-11T21:54:44Z</dc:date>
    </item>
    <item>
      <title>Re: Update a variable using a substraction of two different datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-a-variable-using-a-substraction-of-two-different-datasets/m-p/550473#M152837</link>
      <description>&lt;PRE&gt;NPT .AliasissueID = OPS.aliasissueid and
NPT .ACCOUNTID = OPS.ACCOUNTID and
NPT .legshares &amp;gt; 0 and
OPS.ASSETMINORCLSSDESC = 'CLASS_I' and&lt;/PRE&gt;
&lt;P&gt;Since you have 3 instances with a space between NPT and a variable name in the code above you are confusing the compiler as to intent. Start by getting the basic syntax correct.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I recall correctly, SAS Proc SQL will currently only allow updating a single variable as well. So you may need to drop the update for&lt;/P&gt;
&lt;PRE&gt;LEG_1_MINUS_LEG_2_SHARES=0&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Apr 2019 23:43:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-a-variable-using-a-substraction-of-two-different-datasets/m-p/550473#M152837</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-04-11T23:43:13Z</dc:date>
    </item>
    <item>
      <title>Re: Update a variable using a substraction of two different datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-a-variable-using-a-substraction-of-two-different-datasets/m-p/550620#M152890</link>
      <description>&lt;P&gt;Yeah, the space was a typo when I copied it to this forum, but I checked in sas and it's correct (without the spaces). I removed the update for&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;LEG_1_MINUS_LEG_2_SHARES=0&lt;/PRE&gt;&lt;P&gt;but the error persists.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2019 13:29:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-a-variable-using-a-substraction-of-two-different-datasets/m-p/550620#M152890</guid>
      <dc:creator>Cristiansg</dc:creator>
      <dc:date>2019-04-12T13:29:42Z</dc:date>
    </item>
  </channel>
</rss>

