<?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: Overwrite or insert rows into new table with PROC SQL in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Overwrite-or-insert-rows-into-new-table-with-PROC-SQL/m-p/531862#M73755</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32246"&gt;@ChrisBrooks&lt;/a&gt;&amp;nbsp;'s suggestion is very straight forward, and also presents the advantage that the table remains sorted (if it's a SAS data set) since you merge BY.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The downside is that you recreate the whole table, so it is wasteful if you want to append a row at the end of a 100m-row table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case the MODIFY statement might be better suited.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 01 Feb 2019 02:37:45 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2019-02-01T02:37:45Z</dc:date>
    <item>
      <title>Overwrite or insert rows into new table with PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Overwrite-or-insert-rows-into-new-table-with-PROC-SQL/m-p/531596#M73748</link>
      <description>&lt;P&gt;Hey guys!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I currently have a programme that generates new records every Sunday for a certain period. Two of the columns in the table are PERIOD_START and PERIOD_END. I want the programme to add the new weeks' records into another table after every run.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently I use INSERT INTO in PROC SQL, which works fine, however if I have a change in source data and need to re-run the programme again mid-week(not a Sunday) it creates duplicate records in my destination table. How can I re-write the PROC SQL so the query first checks if the PERIOD_START and PERIOD_END dates from the new table match in the destination table and:&lt;/P&gt;&lt;P&gt;1. If they do - overwrite the rows with the new data&lt;/P&gt;&lt;P&gt;2. If they don't - just execute the insert into.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jan 2019 10:18:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Overwrite-or-insert-rows-into-new-table-with-PROC-SQL/m-p/531596#M73748</guid>
      <dc:creator>sasnewbiexx</dc:creator>
      <dc:date>2019-01-31T10:18:20Z</dc:date>
    </item>
    <item>
      <title>Re: Overwrite or insert rows into new table with PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Overwrite-or-insert-rows-into-new-table-with-PROC-SQL/m-p/531837#M73752</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/259057"&gt;@sasnewbiexx&lt;/a&gt;&amp;nbsp;and welcome to the community.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you need to use Proc SQL as a data step merge would be much simpler - automatically overwriting records with matching period_start and period_end values and inserting those which don't?&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jan 2019 23:40:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Overwrite-or-insert-rows-into-new-table-with-PROC-SQL/m-p/531837#M73752</guid>
      <dc:creator>ChrisBrooks</dc:creator>
      <dc:date>2019-01-31T23:40:23Z</dc:date>
    </item>
    <item>
      <title>Re: Overwrite or insert rows into new table with PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Overwrite-or-insert-rows-into-new-table-with-PROC-SQL/m-p/531862#M73755</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32246"&gt;@ChrisBrooks&lt;/a&gt;&amp;nbsp;'s suggestion is very straight forward, and also presents the advantage that the table remains sorted (if it's a SAS data set) since you merge BY.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The downside is that you recreate the whole table, so it is wasteful if you want to append a row at the end of a 100m-row table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case the MODIFY statement might be better suited.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 02:37:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Overwrite-or-insert-rows-into-new-table-with-PROC-SQL/m-p/531862#M73755</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-02-01T02:37:45Z</dc:date>
    </item>
    <item>
      <title>Re: Overwrite or insert rows into new table with PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Overwrite-or-insert-rows-into-new-table-with-PROC-SQL/m-p/531870#M73756</link>
      <description>&lt;P&gt;MODIFY works like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data MASTER_TABLE(index=(X)); 
  retain Y 1;       
  do X=1 to 1e7;
    output; 
  end;   
run;

data UPDATE_TABLE;
  retain Y 2;       
  do X=0 to 1;
    output; 
  end;   
run;
        
data MASTER_TABLE;
  modify MASTER_TABLE 
         UPDATE_TABLE ;
  by X;
  select (_IORC_);
    when (%sysrc(_sok))  replace;  %* Update observation;
    when (%sysrc(_dsenmr)) do;     %* Add observation;
      output;  
      _ERROR_=0;
    end;
    otherwise do;                  %* Unexpected value;
      putlog 'An unexpected I/O error has occurred.';  
      stop;
    end; 
  end; 
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 Feb 2019 03:34:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Overwrite-or-insert-rows-into-new-table-with-PROC-SQL/m-p/531870#M73756</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-02-01T03:34:32Z</dc:date>
    </item>
    <item>
      <title>Re: Overwrite or insert rows into new table with PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Overwrite-or-insert-rows-into-new-table-with-PROC-SQL/m-p/532514#M73787</link>
      <description>Thank you very much, guys! The suggestion &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt; worked fined for me.</description>
      <pubDate>Mon, 04 Feb 2019 07:45:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Overwrite-or-insert-rows-into-new-table-with-PROC-SQL/m-p/532514#M73787</guid>
      <dc:creator>sasnewbiexx</dc:creator>
      <dc:date>2019-02-04T07:45:28Z</dc:date>
    </item>
  </channel>
</rss>

