<?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 Update table in proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Update-table-in-proc-sql/m-p/584454#M166472</link>
    <description>&lt;P&gt;I want to update the ir.INSURANCE_CF dataset which should have the value for the variable &lt;CODE class=" language-sas"&gt;INSURANCE_CONTRACT_GROUP_ID&lt;/CODE&gt; per the below calculation. With the below code I could only recreate the ir.INSURANCE_CF dataset&amp;nbsp; whereas I was asked to only update the dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way that we can tweak the code below to update the original dataset instead of recreating the same?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 28 Aug 2019 11:37:44 GMT</pubDate>
    <dc:creator>Babloo</dc:creator>
    <dc:date>2019-08-28T11:37:44Z</dc:date>
    <item>
      <title>Update table in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-table-in-proc-sql/m-p/584454#M166472</link>
      <description>&lt;P&gt;I want to update the ir.INSURANCE_CF dataset which should have the value for the variable &lt;CODE class=" language-sas"&gt;INSURANCE_CONTRACT_GROUP_ID&lt;/CODE&gt; per the below calculation. With the below code I could only recreate the ir.INSURANCE_CF dataset&amp;nbsp; whereas I was asked to only update the dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way that we can tweak the code below to update the original dataset instead of recreating the same?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Aug 2019 11:37:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-table-in-proc-sql/m-p/584454#M166472</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2019-08-28T11:37:44Z</dc:date>
    </item>
    <item>
      <title>Re: Update table in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-table-in-proc-sql/m-p/584461#M166475</link>
      <description>&lt;P&gt;Could you please try the below code, we do not need to name the new variable as &lt;CODE class=" language-sas"&gt;INSURANCE_CONTRACT_GROUP_ID&lt;/CODE&gt;_NEW, instead use the same existing name &lt;CODE class=" language-sas"&gt;INSURANCE_CONTRACT_GROUP_ID&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table ir.INSURANCE_CF as
select
  a.*,
  b.INITIAL_RECOGNITION_DT,
  compress(cats(a.INSURANCE_CONTRACT_GROUP_ID,put(a.ISSUE_DT,date9.),put(b.INITIAL_RECOGNITION_DT,date9.)),'.')
  as INSURANCE_CONTRACT_GROUP_ID length=72
from IFRSLDIS.INSURANCE_CASHFLOW  as a
left join IFRSLDIS.ADP_OUTPUT_NON_LIFE as b
on
  a.REPORTING_DT = b.REPORTING_DT and
  a.ENTITY_ID = b.UNIT and
cats(substr(put(ISSUE_DT,yymmn6.),1,4),"-",substr(put(ISSUE_DT,yymmn6.),5)) = b.ISSUE_MONTH
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Aug 2019 08:08:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-table-in-proc-sql/m-p/584461#M166475</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-08-28T08:08:21Z</dc:date>
    </item>
    <item>
      <title>Re: Update table in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-table-in-proc-sql/m-p/584466#M166479</link>
      <description>It is recreating the table, right? I just want to update the permanent&lt;BR /&gt;table with updated field values for that variable based on the below&lt;BR /&gt;calculation&lt;BR /&gt;</description>
      <pubDate>Wed, 28 Aug 2019 08:17:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-table-in-proc-sql/m-p/584466#M166479</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2019-08-28T08:17:35Z</dc:date>
    </item>
    <item>
      <title>Re: Update table in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-table-in-proc-sql/m-p/584467#M166480</link>
      <description>&lt;P&gt;Since you change the structure, you can't update, only rewrite.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2019 08:21:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-table-in-proc-sql/m-p/584467#M166480</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-08-28T08:21:20Z</dc:date>
    </item>
    <item>
      <title>Re: Update table in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-table-in-proc-sql/m-p/584468#M166481</link>
      <description>I'm not changing the structure of the table. I just want to populate the&lt;BR /&gt;updated values in one variable as I mentioned in my OP&lt;BR /&gt;</description>
      <pubDate>Wed, 28 Aug 2019 08:23:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-table-in-proc-sql/m-p/584468#M166481</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2019-08-28T08:23:35Z</dc:date>
    </item>
    <item>
      <title>Re: Update table in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-table-in-proc-sql/m-p/584470#M166483</link>
      <description>&lt;P&gt;I don't see an opportunity for an update anyway, as you use&lt;/P&gt;
&lt;PRE&gt;IFRSLDIS.INSURANCE_CASHFLOW
IFRSLDIS.ADP_OUTPUT_NON_LIFE&lt;/PRE&gt;
&lt;P&gt;as input to create a completely new dataset. You do not read&lt;/P&gt;
&lt;PRE&gt;ir.INSURANCE_CF&lt;/PRE&gt;
&lt;P&gt;anywhere in your code.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2019 08:32:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-table-in-proc-sql/m-p/584470#M166483</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-08-28T08:32:25Z</dc:date>
    </item>
    <item>
      <title>Re: Update table in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-table-in-proc-sql/m-p/584472#M166484</link>
      <description>&lt;P&gt;BTW, why do you still use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;cats(substr(put(ISSUE_DT,yymmn6.),1,4),"-",substr(put(ISSUE_DT,yymmn6.),5))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;when&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;put(ISSUE_DT,yymmd7.)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;achieves the same (as I showed in your &lt;A href="https://communities.sas.com/t5/SAS-Programming/Optimization/m-p/584137" target="_blank" rel="noopener"&gt;previous thread&lt;/A&gt;)?&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2019 08:41:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-table-in-proc-sql/m-p/584472#M166484</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-08-28T08:41:25Z</dc:date>
    </item>
    <item>
      <title>Re: Update table in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-table-in-proc-sql/m-p/584473#M166485</link>
      <description>There is a typo.&lt;BR /&gt;&lt;BR /&gt;ir. should be read as IFRSLDIS.&lt;BR /&gt;&lt;BR /&gt;I want to update IFRSLDIS.Insurance_Cashflow table.&lt;BR /&gt;</description>
      <pubDate>Wed, 28 Aug 2019 08:45:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-table-in-proc-sql/m-p/584473#M166485</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2019-08-28T08:45:35Z</dc:date>
    </item>
    <item>
      <title>Re: Update table in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-table-in-proc-sql/m-p/584475#M166486</link>
      <description>&lt;P&gt;See this quick example for updating an&amp;nbsp;&lt;EM&gt;existing&lt;/EM&gt; column with data from another table:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
set sashelp.class;
run;

data class1;
set sashelp.class (keep=Name);
x1 = _N_;
run;

proc sql;
update class a
set age = (select x1 from class1 b where b.name = a.name)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Aug 2019 08:55:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-table-in-proc-sql/m-p/584475#M166486</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-08-28T08:55:10Z</dc:date>
    </item>
    <item>
      <title>Re: Update table in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-table-in-proc-sql/m-p/584483#M166495</link>
      <description>&lt;P&gt;I got it. Could you please tell me how will you optimize the code below to update the permanent table?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;I'm trying to do optimize the above second step as follows, but I couldn't succeed as I'm not certain how to set the values in &lt;CODE class=" language-sas"&gt;INSURANCE_CONTRACT_GROUP_ID&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;I've 16 columns in IFRSLDIS.INSURANCE_CASHFLOW and therefore I should have same columns in the final result with updated values for &lt;CODE class=" language-sas"&gt;INSURANCE_CONTRACT_GROUP_ID&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2019 11:38:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-table-in-proc-sql/m-p/584483#M166495</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2019-08-28T11:38:50Z</dc:date>
    </item>
    <item>
      <title>Re: Update table in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-table-in-proc-sql/m-p/584491#M166498</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What does the SAS log tell you when you execute the SQL as posted?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. A SQL update can only change values in existing cells. It can NOT add columns or rows. So: Any DROP statement is already wrong.&lt;/P&gt;
&lt;P&gt;2. You update CELLS and for this reason the sub-select must return exactly one value. The sub-select must also be valid SQL code which yours isn't.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select * from temp compress(cats(INSURANCE_CONTRACT_GROUP_ID,put(ISSUE_DT,date9.),put(INITIAL_RECOGNITION_DT,date9.)),.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please try and check that again - like all cats() stuff needs to go into the select clause and you also need to add a where condition to only select the row which matches the record in the table you want to update. May be try first to fully understand the sample code&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;posted and also read up how a SQL Update works in documentation.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://go.documentation.sas.com/?docsetId=sqlproc&amp;amp;docsetTarget=p0z9p6hclwnhxin1mrewxhdz5f26.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://go.documentation.sas.com/?docsetId=sqlproc&amp;amp;docsetTarget=p0z9p6hclwnhxin1mrewxhdz5f26.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2019 10:39:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-table-in-proc-sql/m-p/584491#M166498</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-08-28T10:39:16Z</dc:date>
    </item>
    <item>
      <title>Re: Update table in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-table-in-proc-sql/m-p/584492#M166499</link>
      <description>&lt;P&gt;I won't waste a second of my time trying to read this ugly piece of spaghetti text.&lt;/P&gt;
&lt;P&gt;Please supply CODE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See my many posts (and those of the other superusers and PROC STARS) for how to write code in a readable manner.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2019 10:34:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-table-in-proc-sql/m-p/584492#M166499</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-08-28T10:34:08Z</dc:date>
    </item>
  </channel>
</rss>

