<?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: How to check if new record is added in a sas dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-new-record-is-added-in-a-sas-dataset/m-p/66201#M14370</link>
    <description>It all depends on how the new record is inserted into your master table and how big your table is.  There are many was to accomplish this functionallity.  &lt;BR /&gt;
&lt;BR /&gt;
I would use any of the 4 methods below:&lt;BR /&gt;
1) I would create a timestamp and the most recent record would be the max timestamp, additional you can create  a new record flag from the transaction set. &lt;BR /&gt;
&lt;BR /&gt;
2) create a new record flag from the incoming data set&lt;BR /&gt;
 See below for a quick code snippet.&lt;BR /&gt;
&lt;BR /&gt;
3) create an audit data set&lt;BR /&gt;
&lt;BR /&gt;
4) create a unique sequential id for your master file and store the max value in another table.  All inserted record would be incremented by 1 then any ID greater than the max id would be new.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data master_table;&lt;BR /&gt;
  format timestamp datetime21.2;&lt;BR /&gt;
  ID=1;value='HELLO';timestamp=datetime();output;&lt;BR /&gt;
  ID=2;value='WORLD';timestamp=datetime();output;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  create table max_id as&lt;BR /&gt;
    select max(id) as max_id&lt;BR /&gt;
	from master_table;&lt;BR /&gt;
  select max_id&lt;BR /&gt;
  into :max_id&lt;BR /&gt;
  from max_id;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
data transaction_table;&lt;BR /&gt;
  value='TEST ';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data master_table;&lt;BR /&gt;
  set master_table (in=inMaster)&lt;BR /&gt;
      transaction_table (in=inTransaction) &lt;BR /&gt;
      ;&lt;BR /&gt;
  * create timestamp to find newest record;&lt;BR /&gt;
  * create 1/0 indicator for newest record;&lt;BR /&gt;
  * increment id by 1;&lt;BR /&gt;
  if inTransaction then do;&lt;BR /&gt;
    counter+1;&lt;BR /&gt;
    timestamp=datetime();&lt;BR /&gt;
    new=(inTransaction);&lt;BR /&gt;
	id=&amp;amp;max_id+counter;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;</description>
    <pubDate>Tue, 17 May 2011 11:27:52 GMT</pubDate>
    <dc:creator>darrylovia</dc:creator>
    <dc:date>2011-05-17T11:27:52Z</dc:date>
    <item>
      <title>How to check if new record is added in a sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-new-record-is-added-in-a-sas-dataset/m-p/66199#M14368</link>
      <description>Hi ,&lt;BR /&gt;
&lt;BR /&gt;
I have a requirement in which on daily basis, I have to find if a new record is added in the dataset and if it is added then I have to use that record for further process. &lt;BR /&gt;
 &lt;BR /&gt;
Please let me know how can I find this through SAS code.&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
SASACC</description>
      <pubDate>Tue, 17 May 2011 08:16:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-new-record-is-added-in-a-sas-dataset/m-p/66199#M14368</guid>
      <dc:creator>SASACC</dc:creator>
      <dc:date>2011-05-17T08:16:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if new record is added in a sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-new-record-is-added-in-a-sas-dataset/m-p/66200#M14369</link>
      <description>You'll need to give some specifics around how your data are organized.  Some examples would be nice as well.</description>
      <pubDate>Tue, 17 May 2011 11:20:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-new-record-is-added-in-a-sas-dataset/m-p/66200#M14369</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2011-05-17T11:20:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if new record is added in a sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-new-record-is-added-in-a-sas-dataset/m-p/66201#M14370</link>
      <description>It all depends on how the new record is inserted into your master table and how big your table is.  There are many was to accomplish this functionallity.  &lt;BR /&gt;
&lt;BR /&gt;
I would use any of the 4 methods below:&lt;BR /&gt;
1) I would create a timestamp and the most recent record would be the max timestamp, additional you can create  a new record flag from the transaction set. &lt;BR /&gt;
&lt;BR /&gt;
2) create a new record flag from the incoming data set&lt;BR /&gt;
 See below for a quick code snippet.&lt;BR /&gt;
&lt;BR /&gt;
3) create an audit data set&lt;BR /&gt;
&lt;BR /&gt;
4) create a unique sequential id for your master file and store the max value in another table.  All inserted record would be incremented by 1 then any ID greater than the max id would be new.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data master_table;&lt;BR /&gt;
  format timestamp datetime21.2;&lt;BR /&gt;
  ID=1;value='HELLO';timestamp=datetime();output;&lt;BR /&gt;
  ID=2;value='WORLD';timestamp=datetime();output;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  create table max_id as&lt;BR /&gt;
    select max(id) as max_id&lt;BR /&gt;
	from master_table;&lt;BR /&gt;
  select max_id&lt;BR /&gt;
  into :max_id&lt;BR /&gt;
  from max_id;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
data transaction_table;&lt;BR /&gt;
  value='TEST ';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data master_table;&lt;BR /&gt;
  set master_table (in=inMaster)&lt;BR /&gt;
      transaction_table (in=inTransaction) &lt;BR /&gt;
      ;&lt;BR /&gt;
  * create timestamp to find newest record;&lt;BR /&gt;
  * create 1/0 indicator for newest record;&lt;BR /&gt;
  * increment id by 1;&lt;BR /&gt;
  if inTransaction then do;&lt;BR /&gt;
    counter+1;&lt;BR /&gt;
    timestamp=datetime();&lt;BR /&gt;
    new=(inTransaction);&lt;BR /&gt;
	id=&amp;amp;max_id+counter;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;</description>
      <pubDate>Tue, 17 May 2011 11:27:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-new-record-is-added-in-a-sas-dataset/m-p/66201#M14370</guid>
      <dc:creator>darrylovia</dc:creator>
      <dc:date>2011-05-17T11:27:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if new record is added in a sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-new-record-is-added-in-a-sas-dataset/m-p/66202#M14371</link>
      <description>hope this helps.&lt;BR /&gt;
you can easily tell the negative.&lt;BR /&gt;
When a table is updated, a timestamp in its header is updated. The following code assumes the data set you want to check, is named yourlib.yourmem&lt;BR /&gt;
 &lt;BR /&gt;
Proc sql noprint; select modate format= datetime19. into :latest_update from dictionary.tables where libname= 'YOURLIB' and memname= 'YOURMEM' ;&lt;BR /&gt;
quit ;&lt;BR /&gt;
%put latest update was &amp;amp;latest_update ;&lt;BR /&gt;
 &lt;BR /&gt;
You can then judge whether this is before or after the last time you reported.&lt;BR /&gt;
  &lt;BR /&gt;
Having the macro variable &amp;amp;latest_update also allows you to use it as a SAS datetime constant, as in these statements&lt;BR /&gt;
 &lt;BR /&gt;
%put represented as %sysfunc( putn( "&amp;amp;latest_update"dt, twmdy ));&lt;BR /&gt;
%put just as date   %sysfunc( putn( "&amp;amp;latest_update"dt,dtdate9));&lt;BR /&gt;
%put time since latest update is %sysfunc( range( %sysfunc(datetime()), "&amp;amp;latest_update"dt), time. );    &lt;BR /&gt;
&lt;BR /&gt;
Additional information is available from the same dictionary table, including "number of observations or rows of data in the table". That can be extracted in the same kind of way. However, since this data might be updated with a new row and have an old row deleted, the number of rows might not change when a new row is added, so I assumed the "modified date" would provide the safest indication of change.&lt;BR /&gt;
&lt;BR /&gt;
 &lt;BR /&gt;
peterC</description>
      <pubDate>Wed, 18 May 2011 06:39:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-new-record-is-added-in-a-sas-dataset/m-p/66202#M14371</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-05-18T06:39:06Z</dc:date>
    </item>
  </channel>
</rss>

