<?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: Ensuring Proc Append does not re-append data that has already been appended in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Ensuring-Proc-Append-does-not-re-append-data-that-has-already/m-p/281644#M59110</link>
    <description>Update is MUCH slower than append so from a performance perspective I wouldn't recommend that.&lt;BR /&gt;Sounds like you don't have control of your process if you think that data can be appended by mistake.&lt;BR /&gt;A macro could be one way of solving it. Another would be to create a unique index. If that's table is large consider use SPDE instead of Base engine.</description>
    <pubDate>Fri, 01 Jul 2016 07:59:08 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2016-07-01T07:59:08Z</dc:date>
    <item>
      <title>Ensuring Proc Append does not re-append data that has already been appended</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Ensuring-Proc-Append-does-not-re-append-data-that-has-already/m-p/281595#M59104</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am looking to create a type 2 data log from type 1 data. Meaning, I have a SAS query that pulls the current open inventory, and I want to log those counts at the end of every week when I run the report so that I collect each week's inventory counts each time I run it so that I have a running / historical list.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As such, I'm using a proc append, but if someone were to run the proc append in error then it may re-append data that's already appended to my new 'base' table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my 'data =' step I have included a today() run date field.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to check whether a date in the 'data' step is equal to the max date in the 'base' table and if so not to append? I want to ensure that I do not continue to append data for the same day if the query is run multiple times a day by accident.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently using:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;Proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;append&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;base&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;= CAIT2.SIU_OPEN_ASSIGNMENTS_HISTORICAL&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;data&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;= GRIDWORK.QUERY_FOR_APPEND_TABLE_0000 &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;force&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;NOTE: The DATA = table includes a field titled&amp;nbsp;'Run_Week' which is an INTNX statement for a date value in the 'data' table. Looking to do the following: If the 'Run_Week'&amp;nbsp;field in the 'data=' table is &amp;gt; the&amp;nbsp;max 'Run_Week' field in the 'base' table then append, else do not append.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Jul 2016 01:17:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Ensuring-Proc-Append-does-not-re-append-data-that-has-already/m-p/281595#M59104</guid>
      <dc:creator>Caisha</dc:creator>
      <dc:date>2016-07-01T01:17:57Z</dc:date>
    </item>
    <item>
      <title>Re: Ensuring Proc Append does not re-append data that has already been appended</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Ensuring-Proc-Append-does-not-re-append-data-that-has-already/m-p/281618#M59107</link>
      <description>&lt;P&gt;Either create a macro, where it firsts checks for the presence of the key variable and then proceeds to append or not as appropriate.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or consider looking into UPDATE statement within a data step.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Jul 2016 04:16:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Ensuring-Proc-Append-does-not-re-append-data-that-has-already/m-p/281618#M59107</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-07-01T04:16:59Z</dc:date>
    </item>
    <item>
      <title>Re: Ensuring Proc Append does not re-append data that has already been appended</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Ensuring-Proc-Append-does-not-re-append-data-that-has-already/m-p/281638#M59109</link>
      <description>&lt;P&gt;We usually solve this by doing a proc sort with nodupkey.&lt;/P&gt;
&lt;P&gt;If you can't identify a sufficient set of key variables, use noduprec or do a proc sql with select distinct *&lt;/P&gt;</description>
      <pubDate>Fri, 01 Jul 2016 06:56:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Ensuring-Proc-Append-does-not-re-append-data-that-has-already/m-p/281638#M59109</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-07-01T06:56:51Z</dc:date>
    </item>
    <item>
      <title>Re: Ensuring Proc Append does not re-append data that has already been appended</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Ensuring-Proc-Append-does-not-re-append-data-that-has-already/m-p/281644#M59110</link>
      <description>Update is MUCH slower than append so from a performance perspective I wouldn't recommend that.&lt;BR /&gt;Sounds like you don't have control of your process if you think that data can be appended by mistake.&lt;BR /&gt;A macro could be one way of solving it. Another would be to create a unique index. If that's table is large consider use SPDE instead of Base engine.</description>
      <pubDate>Fri, 01 Jul 2016 07:59:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Ensuring-Proc-Append-does-not-re-append-data-that-has-already/m-p/281644#M59110</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-07-01T07:59:08Z</dc:date>
    </item>
    <item>
      <title>Re: Ensuring Proc Append does not re-append data that has already been appended</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Ensuring-Proc-Append-does-not-re-append-data-that-has-already/m-p/281975#M59150</link>
      <description>&lt;P&gt;If the data volumes are high and performance is important (something greater 1M rows and processing within seconds) then I'd go for a control table where you store the last date loaded.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If above is not really of concern then you could go for some code as below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data history_rec;
  do week=1 to 10;
    count=ceil(ranuni(1)*20);
    output;
  end;
run;

data new_rec;
    do week=6,8,11,12;
    count=ceil(ranuni(1)*20);
    output;
  end;
run;

proc sql noprint;
  select max(week) into :max_week
  from history_rec
  ;
quit;

proc append base=history_rec data=new_rec(where=(week&amp;gt;&amp;amp;max_week));
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Jul 2016 10:51:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Ensuring-Proc-Append-does-not-re-append-data-that-has-already/m-p/281975#M59150</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-07-04T10:51:22Z</dc:date>
    </item>
  </channel>
</rss>

