<?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: Best way to do SQL Update from another table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-do-SQL-Update-from-another-table/m-p/836255#M330661</link>
    <description>&lt;P&gt;Sorry, I didnt make it clear.&lt;/P&gt;&lt;P&gt;I wish to proc append the join temp table to postgresql as a temp table and not physical table in SAS.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 01 Oct 2022 02:03:50 GMT</pubDate>
    <dc:creator>WaiLoon</dc:creator>
    <dc:date>2022-10-01T02:03:50Z</dc:date>
    <item>
      <title>Best way to do SQL Update from another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-do-SQL-Update-from-another-table/m-p/835742#M330424</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to update my current working table from source database table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Update HardwareList tgt&lt;/P&gt;&lt;P&gt;SET&amp;nbsp; &amp;nbsp; &amp;nbsp;Remark = (SELECT Remark FROM TmpHW WHERE&amp;nbsp;tgt.ID = TmpHW.ID and InsertUpdate = 'U')&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;,Status = (SELECT Status FROM TmpHW WHERE&amp;nbsp;tgt.ID= TmpHW.ID and InsertUpdate = 'U')&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;,DecomDate = (SELECT DecomDate FROM TmpHW WHERE&amp;nbsp;tgt.ID = TmpHW.ID and InsertUpdate = 'U')&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;,DecomReason = (SELECT DecomReason FROM TmpHW WHERE&amp;nbsp;tgt.ID = TmpHW.ID and InsertUpdate = 'U')&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to have 1 select statement for each field that I need to update, if i got 30 fields need to update means I need 30 select statement and I worry this will cause the performance issue cause too many extraction.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any best method to do update?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Other database system like MSSQL, MySQL, PostgreSQL, the update statement can be very simple&lt;/P&gt;&lt;P&gt;example&lt;/P&gt;&lt;P&gt;Update HardwareList tgt&lt;/P&gt;&lt;P&gt;SET&amp;nbsp; &amp;nbsp; &amp;nbsp;Remark = Remark&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;,Status = Status&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;,DecomDate = DecomDate&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;,DecomReason = DecomReason&lt;/P&gt;&lt;P&gt;FROM TmpHW WHERE&amp;nbsp;tgt.ID = TmpHW.ID and InsertUpdate = 'U'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I really having issue with the performance for the update, and I really hope to see if there are any way to improve it.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2022 02:25:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-do-SQL-Update-from-another-table/m-p/835742#M330424</guid>
      <dc:creator>WaiLoon</dc:creator>
      <dc:date>2022-09-29T02:25:16Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to do SQL Update from another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-do-SQL-Update-from-another-table/m-p/835758#M330431</link>
      <description>&lt;P&gt;Are you updating an external database ? If so is that data coming from SAS or from the external database? If you are updating an external database from SAS then one easy way is to load a temporary table into the database from SAS and then run an SQL database query updating from the temporary table. SQL Passthru allows you to run database-specific SQL from SAS.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2022 03:03:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-do-SQL-Update-from-another-table/m-p/835758#M330431</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-09-29T03:03:34Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to do SQL Update from another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-do-SQL-Update-from-another-table/m-p/835759#M330432</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;Thanks for fast reply.&lt;/P&gt;&lt;P&gt;Yes, I'm updating to PostgreSQL from SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Temp table means physical table or just table in memory??&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you have sample or details??&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How I do now is, I create a tmp table with all data I need from SAS table&lt;/P&gt;&lt;P&gt;Then I have 1 extra column call InsertUpdate, this column will differentiate whether the record is new or existing.&lt;/P&gt;&lt;P&gt;then Insert into PostgreSQL for InsertUpdate = 'I' and update data if InsertUpdate = 'U'.&lt;/P&gt;&lt;P&gt;I have create index key in postgreSQL for the updating but still very slow.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2022 03:17:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-do-SQL-Update-from-another-table/m-p/835759#M330432</guid>
      <dc:creator>WaiLoon</dc:creator>
      <dc:date>2022-09-29T03:17:49Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to do SQL Update from another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-do-SQL-Update-from-another-table/m-p/835761#M330434</link>
      <description>&lt;P&gt;If you are either updating or inserting all columns in a row, then one easy way is to delete the rows you are updating and just do a single insert. Does that work for you? It is easy to insert from a SAS table using PROC DATASETS with the APPEND statement.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2022 03:49:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-do-SQL-Update-from-another-table/m-p/835761#M330434</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-09-29T03:49:09Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to do SQL Update from another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-do-SQL-Update-from-another-table/m-p/835769#M330436</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;Thanks for the reply.&lt;/P&gt;&lt;P&gt;Actually I can't do that, reason is the target table contain data from source and also user input value.&lt;/P&gt;&lt;P&gt;Some fields are updating from SAS, but some fields are user input from the web ui. so I can't delete the record.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Btw, how to do the Proc Dataset with Append?&lt;/P&gt;&lt;P&gt;I'm new to SAS, I'm only good at SQL, so now sure how to do that...&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2022 08:28:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-do-SQL-Update-from-another-table/m-p/835769#M330436</guid>
      <dc:creator>WaiLoon</dc:creator>
      <dc:date>2022-09-29T08:28:50Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to do SQL Update from another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-do-SQL-Update-from-another-table/m-p/835923#M330508</link>
      <description>&lt;P&gt;This is how I would load into an SQL Server temporary table:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname tempdb odbc noprompt = "server=MySQLServer;DRIVER=SQL Server Native Client 11.0;Trusted_Connection=yes;DATABASE=tempdb;" Schema = DBO;

proc datasets library = tempdb;
  append base = MySQLTempTable
         data = work.MySASTempTable 
         ;
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It will be a bit different for Postgres.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2022 19:09:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-do-SQL-Update-from-another-table/m-p/835923#M330508</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-09-29T19:09:25Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to do SQL Update from another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-do-SQL-Update-from-another-table/m-p/835979#M330533</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just to make sure i understand correctly&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Create a temp table (tmpHW) in postgresql&lt;/P&gt;&lt;P&gt;2. Insert source table to the tmpHW&lt;/P&gt;&lt;P&gt;3. Update the tmpHW data to Hardware table using SQL&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this the steps?&amp;nbsp;&lt;/P&gt;&lt;P&gt;and how about the append you mentioned?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry, i really need help on this cause really dont know SAS code.&lt;/P&gt;&lt;P&gt;The code you show me look very simple and it create the temp table within few seconds.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to understand, how do i insert new record from the tmpHW to Hardware and also Update the data from tmpHW to Hardware using SAS code??&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can show some sample??&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is possible i prepare the temp data table in proc sql... then from proc datasets append the data table to postgresql?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2022 00:46:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-do-SQL-Update-from-another-table/m-p/835979#M330533</guid>
      <dc:creator>WaiLoon</dc:creator>
      <dc:date>2022-09-30T00:46:47Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to do SQL Update from another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-do-SQL-Update-from-another-table/m-p/835981#M330534</link>
      <description>&lt;P&gt;Since you appear to be knowledgeable in database SQL you can use genuine PostgreSQL SQL syntax like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname PostgreS odbc noprompt = "server=MySQLServer;DRIVER=SQL Server Native Client 11.0;Trusted_Connection=yes;DATABASE=tempdb;" Schema = DBO;

proc sql;
   connect using PostgreS; 
   execute (update MyDatabase.MySchema.MyTable
   &amp;lt; PostgreSQL Update SQL statements&amp;gt;
           ) by PostgreS;
   disconnect from PostgreS;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Having the SAS table loaded as a database temporary table means you can refer to that in the above example to do updates.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2022 01:19:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-do-SQL-Update-from-another-table/m-p/835981#M330534</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-09-30T01:19:54Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to do SQL Update from another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-do-SQL-Update-from-another-table/m-p/835982#M330535</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;.. using PROC DATASETS with the APPEND statement.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Also known as PROC APPEND.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2022 01:29:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-do-SQL-Update-from-another-table/m-p/835982#M330535</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-30T01:29:56Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to do SQL Update from another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-do-SQL-Update-from-another-table/m-p/836006#M330551</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;Then may I know how to delete the temp table??&lt;/P&gt;&lt;P&gt;I plan to do&lt;/P&gt;&lt;P&gt;1. Insert whatever new record from SAS to postgresql using normal "proc sql"&lt;/P&gt;&lt;P&gt;2. use "proc append" to copy the table from SAS to postgresql as a temp table&lt;/P&gt;&lt;P&gt;3. then use "execute" to run normal SQL statement to do the data update&amp;nbsp;&lt;/P&gt;&lt;P&gt;4. delete the temp table from postgresql&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but i'm not sure how to do the delete like the "proc append".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And also wish to know if i use "proc append" to copy a temp table to postgresql instead of physical table?&amp;nbsp;&lt;/P&gt;&lt;P&gt;example&lt;/P&gt;&lt;P&gt;I create a tmptable and join few column from few different table, then copy this tmptable to postgresql.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2022 06:29:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-do-SQL-Update-from-another-table/m-p/836006#M330551</guid>
      <dc:creator>WaiLoon</dc:creator>
      <dc:date>2022-09-30T06:29:29Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to do SQL Update from another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-do-SQL-Update-from-another-table/m-p/836017#M330557</link>
      <description>&lt;P&gt;DROP TABLE should be available in Postgres SQL, so you use it in the pass-through.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2022 07:46:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-do-SQL-Update-from-another-table/m-p/836017#M330557</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-09-30T07:46:01Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to do SQL Update from another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-do-SQL-Update-from-another-table/m-p/836054#M330583</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;I got 1 more question.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I create a tmptable and join few column from few different table, then copy this tmptable to postgresql.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;CREATE TABLE Temp1 AS 
SELECT HW.Id, HW.Name, HW.Status, Type.TypeName
FROM   source.HW
INNER JOIN source.Type
ON Type.TypeID = HW.TypeID

;

proc datasets library = source;
  	append base = SASHardwareTable
           data = Temp1
    ;
run;
quit;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Sep 2022 12:45:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-do-SQL-Update-from-another-table/m-p/836054#M330583</guid>
      <dc:creator>WaiLoon</dc:creator>
      <dc:date>2022-09-30T12:45:05Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to do SQL Update from another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-do-SQL-Update-from-another-table/m-p/836213#M330647</link>
      <description>&lt;P&gt;And what is your question?&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2022 20:28:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-do-SQL-Update-from-another-table/m-p/836213#M330647</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-09-30T20:28:09Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to do SQL Update from another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-do-SQL-Update-from-another-table/m-p/836255#M330661</link>
      <description>&lt;P&gt;Sorry, I didnt make it clear.&lt;/P&gt;&lt;P&gt;I wish to proc append the join temp table to postgresql as a temp table and not physical table in SAS.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 01 Oct 2022 02:03:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-do-SQL-Update-from-another-table/m-p/836255#M330661</guid>
      <dc:creator>WaiLoon</dc:creator>
      <dc:date>2022-10-01T02:03:50Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to do SQL Update from another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-do-SQL-Update-from-another-table/m-p/836256#M330662</link>
      <description>&lt;P&gt;You first create the temp table&amp;nbsp;&lt;EM&gt;in the database&lt;/EM&gt; (not in WORK), then you use INSERT INTO &lt;U&gt;in explicit pass-through&lt;/U&gt; to append the data to the "master". In explicit pass-through (&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/sqlproc/n0tpd3yaqvep53n1g8wahav3hgco.htm" target="_blank" rel="noopener"&gt;EXECUTE BY&lt;/A&gt;), you use the syntax of the database's SQL.&lt;/P&gt;</description>
      <pubDate>Sat, 01 Oct 2022 03:25:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-do-SQL-Update-from-another-table/m-p/836256#M330662</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-10-01T03:25:59Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to do SQL Update from another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-do-SQL-Update-from-another-table/m-p/836337#M330683</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/421594"&gt;@WaiLoon&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below some fully functional sample code that hopefully will show you the way.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* options to write to the SAS log more info how SAS interacts with the DB */
options sastrace=',,,d' sastraceloc=saslog nostsuffix;

/* define common libname options */
%let pg_conn_common=
  DATABASE=&amp;lt;pg database name&amp;gt;  
  SERVER="&amp;lt;pg server name&amp;gt;" 
  PORT=&amp;lt;port used by SAS to connect to PG&amp;gt; 
  authdomain=&amp;lt;authdomain as defined in SAS metadata - alternatively use user/password&amp;gt; 
  DBMAX_TEXT=32000  
  DIRECT_EXE=DELETE  
  DBCLIENT_MAX_BYTES=1 
  ;

/* libname for permanent pg table to be updated           */
/* - GLOBAL connection required to use pg temporar tables */
LIBNAME pg_perm POSTGRES  
  CONNECTION=GLOBAL  
  SCHEMA="&amp;lt;pg schema name of permanent master table&amp;gt;"
  &amp;amp;pg_conn_common
  ;

/* libname for temporary pg table with updates                     */
/* - pg temporar table don't have a schema                         */
/* - pg temporary tables only exist within the scope of a session  */
/*   and are only accessible within the scope of a session         */
/*   (similar to SAS Work tables)                                  */                           
LIBNAME pg_temp POSTGRES  
  CONNECTION=GLOBAL  
  DBMSTEMP=YES  
  &amp;amp;pg_conn_common 
  ;

/* macro to drop tables if they exist */
%macro drop_tbl_if_exists(lref_tbl);
  %if %sysfunc(exist(&amp;amp;lref_tbl)) %then
    %do;
      proc sql;
        drop table &amp;amp;lref_tbl;
      quit;
    %end;
%mend;

/* drop tables to make sample code re-runnable */
/* - NB: PG temporary tables only exists during a session */
%drop_tbl_if_exists(pg_perm.class);
%drop_tbl_if_exists(pg_temp.class_updt);

/* load SAS master table into pg permanent table         */
/* - SAS will create the pg table if it doesn't exist    */
/*   inspect SAS log more detail                         */
proc append base=pg_perm.class data=sashelp.class;
run;quit;

/* create table for updates in SAS Work */
data work.class_updt;
  set sashelp.class;
  if name='Alice' then 
    do;
      age=99;
      output;
    end;
  if name in ('Alfred','Jane') then
    do;
      weight=-10;
      output;
    end;
run;

/* load SAS update table into pg temp table              */
/* - SAS will create the pg table if it doesn't exist    */
/*   inspect SAS log more detail                         */

proc append base=pg_temp.class_updt data=work.class_updt;
run;quit;

/* print pg temp table */
proc sql;
  select *
  from pg_temp.class_updt
  order by name;
quit;

/* update master table with temp table                             */
/* - using explicit SQL pass-through                               */
/* - executes fully in-database; SAS just sends the code to the DB */
/* - SQL within the execute() block must be in Postgres syntax     */
proc sql;
  connect using pg_perm;
  execute by pg_perm
    (
      update prepsegdr.class m
        set age=t.age, weight=t.weight
        from class_updt t
        where m.name=t.name;
    );
  disconnect from pg_perm;
quit;

/* print pg master table after update */
proc sql;
  select *
  from pg_perm.class
  order by name;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1664673778698.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/75787i56B2B1C22CCB9E62/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1664673778698.png" alt="Patrick_0-1664673778698.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The "common" libname connection options might need to be different in your environment (like for dbclient_max_bytes). You find that documented &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/acreldb/n0fjl64b6o5qvon1wpzprpfom8au.htm" target="_self"&gt;here&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Easiest is normally to use an already existing and working libname as your starting point.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The bits that are not in the common section are MUST and will be the same for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm showing an example for an UPDATE but of course once you've loaded all your data into Postgres tables it's just Postgres SQL you need for any other operation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 02 Oct 2022 01:31:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-do-SQL-Update-from-another-table/m-p/836337#M330683</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-10-02T01:31:16Z</dc:date>
    </item>
  </channel>
</rss>

