<?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: Append data to a table and increment a flag on the resultant table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Append-data-to-a-table-and-increment-a-flag-on-the-resultant/m-p/652562#M195933</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/259982"&gt;@Sudhan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks for your response. But i need the DT_FLAG&amp;gt;=2, as this data will be used for a report.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Can you show exactly how the DT_Flag variable is used in your report?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might be surprised what could be done with your datetime variable without changing values of a variable.&lt;/P&gt;
&lt;P&gt;Or add the flag just before preparing the report. I find the idea of permanent data sets with values changing to be worrisome.&lt;/P&gt;</description>
    <pubDate>Tue, 02 Jun 2020 14:30:18 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-06-02T14:30:18Z</dc:date>
    <item>
      <title>Append data to a table and increment a flag on the resultant table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-data-to-a-table-and-increment-a-flag-on-the-resultant/m-p/652476#M195890</link>
      <description>&lt;DIV class="votecell post-layout--left"&gt;&lt;DIV class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200"&gt;&lt;SPAN style="font-family: inherit;"&gt;I have two tables on SAS "Table_A" and "Table_A_Archive", as part my ETL process "Table_A" is created on a daily basis and the data should be archived on "Table_A_Archive". When the data is archived on "Table_A_Archive" a a flag will be created/updated "DT_FLAG".&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="postcell post-layout--right"&gt;&lt;DIV class="post-text"&gt;&lt;P&gt;On the first day this is how the table would look like&lt;/P&gt;&lt;PRE class="lang-sql prettyprint prettyprinted"&gt;&lt;CODE&gt; &lt;SPAN class="str"&gt;"Table_A"&lt;/SPAN&gt;
 &lt;SPAN class="pun"&gt;|&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; ID  &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;|&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; Load_Date
 &lt;/SPAN&gt;&lt;SPAN class="com"&gt;------ -------------&lt;/SPAN&gt;
 &lt;SPAN class="pun"&gt;|&lt;/SPAN&gt; &lt;SPAN class="lit"&gt;100&lt;/SPAN&gt; &lt;SPAN class="pun"&gt;|&lt;/SPAN&gt; &lt;SPAN class="lit"&gt;01&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;JUN2020&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;:&lt;/SPAN&gt;&lt;SPAN class="lit"&gt;12&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;:&lt;/SPAN&gt;&lt;SPAN class="lit"&gt;13&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;:&lt;/SPAN&gt;&lt;SPAN class="lit"&gt;56&lt;/SPAN&gt;

 &lt;SPAN class="str"&gt;"Table_A_Archive"&lt;/SPAN&gt;
  &lt;SPAN class="pun"&gt;|&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; ID  &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;|&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; Load_Date           &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;|&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; DT_FLAG
  &lt;/SPAN&gt;&lt;SPAN class="com"&gt;------ --------------------- ---------&lt;/SPAN&gt;
  &lt;SPAN class="pun"&gt;|&lt;/SPAN&gt; &lt;SPAN class="lit"&gt;100&lt;/SPAN&gt; &lt;SPAN class="pun"&gt;|&lt;/SPAN&gt; &lt;SPAN class="lit"&gt;01&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;JUN2020&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;:&lt;/SPAN&gt;&lt;SPAN class="lit"&gt;12&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;:&lt;/SPAN&gt;&lt;SPAN class="lit"&gt;13&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;:&lt;/SPAN&gt;&lt;SPAN class="lit"&gt;56&lt;/SPAN&gt;  &lt;SPAN class="pun"&gt;|&lt;/SPAN&gt; &lt;SPAN class="lit"&gt;1&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;On Day 2&lt;/P&gt;&lt;PRE class="lang-sql prettyprint prettyprinted"&gt;&lt;CODE&gt; &lt;SPAN class="str"&gt;"Table_A"&lt;/SPAN&gt;
 &lt;SPAN class="pun"&gt;|&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; ID  &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;|&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; Load_Date
 &lt;/SPAN&gt;&lt;SPAN class="com"&gt;------ ------------&lt;/SPAN&gt;
 &lt;SPAN class="pun"&gt;|&lt;/SPAN&gt; &lt;SPAN class="lit"&gt;101&lt;/SPAN&gt; &lt;SPAN class="pun"&gt;|&lt;/SPAN&gt; &lt;SPAN class="lit"&gt;02&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;JUN2020&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;:&lt;/SPAN&gt;&lt;SPAN class="lit"&gt;12&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;:&lt;/SPAN&gt;&lt;SPAN class="lit"&gt;13&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;:&lt;/SPAN&gt;&lt;SPAN class="lit"&gt;56&lt;/SPAN&gt;

 &lt;SPAN class="str"&gt;"Table_A_Archive"&lt;/SPAN&gt;
 &lt;SPAN class="pun"&gt;|&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; ID  &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;|&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; Load_Date           &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;|&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; DT_FLAG
 &lt;/SPAN&gt;&lt;SPAN class="com"&gt;------ --------------------- ---------&lt;/SPAN&gt;
 &lt;SPAN class="pun"&gt;|&lt;/SPAN&gt; &lt;SPAN class="lit"&gt;100&lt;/SPAN&gt; &lt;SPAN class="pun"&gt;|&lt;/SPAN&gt; &lt;SPAN class="lit"&gt;01&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;JUN2020&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;:&lt;/SPAN&gt;&lt;SPAN class="lit"&gt;12&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;:&lt;/SPAN&gt;&lt;SPAN class="lit"&gt;13&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;:&lt;/SPAN&gt;&lt;SPAN class="lit"&gt;56&lt;/SPAN&gt;  &lt;SPAN class="pun"&gt;|&lt;/SPAN&gt; &lt;SPAN class="lit"&gt;2&lt;/SPAN&gt;
 &lt;SPAN class="pun"&gt;|&lt;/SPAN&gt; &lt;SPAN class="lit"&gt;101&lt;/SPAN&gt; &lt;SPAN class="pun"&gt;|&lt;/SPAN&gt; &lt;SPAN class="lit"&gt;02&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;JUN2020&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;:&lt;/SPAN&gt;&lt;SPAN class="lit"&gt;12&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;:&lt;/SPAN&gt;&lt;SPAN class="lit"&gt;13&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;:&lt;/SPAN&gt;&lt;SPAN class="lit"&gt;56&lt;/SPAN&gt;  &lt;SPAN class="pun"&gt;|&lt;/SPAN&gt; &lt;SPAN class="lit"&gt;1&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The new data should be loaded with the DT_FLAG of 1 and old records DT_FLAG should be incremented by 1. Load_Date is the pivotal point. I have written a SAS code but it seems a bit messy, can someone please help me with a SAS Datastep&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro Cntl_archive(table_name=,arch_table_name=);
 %GLOBAL WRK;

 %if %sysfunc(exist(&amp;amp;arch_table_name.))  %then %do;

 proc append base=&amp;amp;arch_table_name. data=&amp;amp;table_name. force;
 run;

 proc sql;
 Create table TEMP as 
 Select distinct Load_Date,Load_Date as WRK from &amp;amp;arch_table_name.
 order by Load_Date desc
 ;quit;

 proc rank data=TEMP descending out=TEMP;
 var WRK;
 ranks count;
 run;

 data &amp;amp;arch_table_name. (drop=DT_FLAG);
 set    &amp;amp;arch_table_name.;
 run;

 proc sql;
 Create table &amp;amp;arch_table_name. as
 Select T0.*,T1.count as DT_FLAG from &amp;amp;arch_table_name. T0
 inner join TEMP T1 on T0.Load_Date=T1.Load_Date
 ;quit
 %end;
 %else %do;

data &amp;amp;arch_table_name.;
set &amp;amp;table_name.;
DT_FLAG= 1; 
IS_ACTIVE='';
run;
%end;
%mend Cntl_archive;&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 02 Jun 2020 10:43:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-data-to-a-table-and-increment-a-flag-on-the-resultant/m-p/652476#M195890</guid>
      <dc:creator>Sudhan</dc:creator>
      <dc:date>2020-06-02T10:43:08Z</dc:date>
    </item>
    <item>
      <title>Re: Append data to a table and increment a flag on the resultant table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-data-to-a-table-and-increment-a-flag-on-the-resultant/m-p/652480#M195892</link>
      <description>&lt;P&gt;To have the DT_FLAG always set to 1 for the most current history record will of course make it easier to then select from the history table BUT this requires that you always update all the history records for the same business key whenever you add a new version. With a growing number of history records ETL performance will degrade ...and that's why I'd consider this a sub-optimal design.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How often do you actually need to select the latest, 2nd latest version, ... from the history table?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I probably wouldn't even create a DT_FLAG/Version_Number at all. The datetime column does this already for you. So just APPEND/INSERT new history records without the need to lookup or even update anything in previously loaded history records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you really need to select "often" from the history table then consider a post process which just sorts the table by business key and datetime - a job on its own which is outside of your actual ETL and though has no impact on the critical path of the end-to-end process.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 11:03:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-data-to-a-table-and-increment-a-flag-on-the-resultant/m-p/652480#M195892</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-06-02T11:03:06Z</dc:date>
    </item>
    <item>
      <title>Re: Append data to a table and increment a flag on the resultant table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-data-to-a-table-and-increment-a-flag-on-the-resultant/m-p/652482#M195893</link>
      <description>Thanks for your response. But i need the DT_FLAG&amp;gt;=2, as this data will be used for a report.</description>
      <pubDate>Tue, 02 Jun 2020 11:05:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-data-to-a-table-and-increment-a-flag-on-the-resultant/m-p/652482#M195893</guid>
      <dc:creator>Sudhan</dc:creator>
      <dc:date>2020-06-02T11:05:19Z</dc:date>
    </item>
    <item>
      <title>Re: Append data to a table and increment a flag on the resultant table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-data-to-a-table-and-increment-a-flag-on-the-resultant/m-p/652488#M195895</link>
      <description>&lt;P&gt;You could also maintain a change_current_ind which is set to 1 for the most current history record and set to 0 for all the others. This way you only ever need to update the most current record in the history table (changing the value from 1 to 0) before you add a new most current record. This will keep the number of rows to update constant.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively: If you sort the history table as proposed then a simple data step if last/first logic will allow to exclude the most current record.&lt;/P&gt;
&lt;P&gt;...or you can also use a SQL &lt;EM&gt;select * from &amp;lt;history table&amp;gt; group by &amp;lt;business key&amp;gt; having max(load_dttm) ne load_dttm&lt;/EM&gt; to exclude the most current record from reporting - and eventually adding an index on the business key will speed-up processing.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 11:18:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-data-to-a-table-and-increment-a-flag-on-the-resultant/m-p/652488#M195895</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-06-02T11:18:00Z</dc:date>
    </item>
    <item>
      <title>Re: Append data to a table and increment a flag on the resultant table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-data-to-a-table-and-increment-a-flag-on-the-resultant/m-p/652498#M195903</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;how about the following process:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Table_A;
infile cards dlm = "|";
input ID Load_Date : datetime21.;
format Load_Date datetime.;
cards;
101 | 02JUN2020:12:13:56
;
run;

data Table_A_Archive;
infile cards dlm = "|";
input ID Load_Date : datetime21. DT_FLAG;
format Load_Date datetime.;
cards;
100 | 01JUN2020:12:13:56 | 1
;
run;
title "Before";
proc print;
run;


/*
the process:
*/

/* create viev */
data Table_A_TMP / view = Table_A_TMP;
  set Table_A;
  DT_FLAG = 0; /* make it 0 flag */
run; 

/* append the data to the history table */
proc append base = Table_A_Archive data = Table_A_TMP;
run;

/* update the flag */
data Table_A_Archive;
  modify Table_A_Archive;
  DT_FLAG = DT_FLAG + 1;
run;
title "After";
proc print;
run;

proc delete data = Table_A_TMP (memtype=view);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 11:32:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-data-to-a-table-and-increment-a-flag-on-the-resultant/m-p/652498#M195903</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-06-02T11:32:16Z</dc:date>
    </item>
    <item>
      <title>Re: Append data to a table and increment a flag on the resultant table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-data-to-a-table-and-increment-a-flag-on-the-resultant/m-p/652509#M195908</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The OP hasn't provided a business key in the sample data - but there must be one. How would your code work if you need to "count-up" by business key and not over all rows?&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 11:46:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-data-to-a-table-and-increment-a-flag-on-the-resultant/m-p/652509#M195908</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-06-02T11:46:22Z</dc:date>
    </item>
    <item>
      <title>Re: Append data to a table and increment a flag on the resultant table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-data-to-a-table-and-increment-a-flag-on-the-resultant/m-p/652522#M195917</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;from what I understood from OP: &amp;gt;&amp;gt;&lt;SPAN&gt;"Table_A" is created on a daily basis and the data should be archived on "Table_A_Archive". When the data is archived on "Table_A_Archive" a a flag will be created/updated "DT_FLAG&lt;/SPAN&gt;&amp;lt;&amp;lt; there is no word about a&amp;nbsp;&lt;SPAN&gt;business key in the data. Just another chunk of data added at the end of the archive and flag updated.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;But assuming that the ID is business key which informs that flag should be increased in old records when the ID is in the latest data, you could try something like this:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Table_A;
infile cards dlm = "|";
input ID Load_Date : datetime21.;
format Load_Date datetime.;
cards;
101 | 02JUN2020:12:13:56
104 | 02JUN2020:12:13:56
;
run;

data Table_A_Archive;
infile cards dlm = "|";
input ID Load_Date : datetime21. DT_FLAG;
format Load_Date datetime.;
cards;
100 | 01JUN2020:12:13:56 | 1
101 | 01JUN2020:12:13:56 | 1
102 | 01JUN2020:12:13:56 | 1
;
run;
title "Before";
proc print;
run;


/*
the process:
*/

/* create viev */
data Table_A_TMP / view = Table_A_TMP;
  set Table_A;
  DT_FLAG = 0; /* make it 0 flag */
run; 

/* append the data to the history table */
proc append base = Table_A_Archive data = Table_A_TMP;
run;

/* update the flag */
data Table_A_Archive;

  if _N_ = 1 then
    do;
      declare hash H(dataset:"Table_A(keep = id)");
      H.defineKey("id");
      H.defineDone();
    end;

  modify Table_A_Archive;
  if H.check() = 0 then DT_FLAG = DT_FLAG + 1;
run;
title "After";
proc print;
run;

proc delete data = Table_A_TMP (memtype=view);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;All the best&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Bart&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 12:47:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-data-to-a-table-and-increment-a-flag-on-the-resultant/m-p/652522#M195917</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-06-02T12:47:00Z</dc:date>
    </item>
    <item>
      <title>Re: Append data to a table and increment a flag on the resultant table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-data-to-a-table-and-increment-a-flag-on-the-resultant/m-p/652530#M195920</link>
      <description>data data_archive;&lt;BR /&gt;done=0;&lt;BR /&gt;do until (done);&lt;BR /&gt;set data_archive end=done;&lt;BR /&gt;DT_FLAG = DT_FLAG+1;&lt;BR /&gt;end;&lt;BR /&gt;done=0;&lt;BR /&gt;do until (done);&lt;BR /&gt;set data_A end=done;&lt;BR /&gt;DT_FLAG = 1;&lt;BR /&gt;end;&lt;BR /&gt;stop;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;As the table size increases the above code becomes less and less performant. If the table is just a record keeper of load dates then it is not an issue.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 02 Jun 2020 13:22:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-data-to-a-table-and-increment-a-flag-on-the-resultant/m-p/652530#M195920</guid>
      <dc:creator>smantha</dc:creator>
      <dc:date>2020-06-02T13:22:51Z</dc:date>
    </item>
    <item>
      <title>Re: Append data to a table and increment a flag on the resultant table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-data-to-a-table-and-increment-a-flag-on-the-resultant/m-p/652547#M195925</link>
      <description>&lt;P&gt;Your unfortunate decision to increase the existing values of the flag requires you to always rewrite the whole dataset. You should have increased the flag for the new observations instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data exist;
input numdata dt_flag;
datalines;
1 1
2 1
3 2
4 2
5 3
6 3
;

data new;
input numdata;
datalines;
7
8
;

data new_app;
set new;
if _n_ = 1
then do;
  set exist (keep=dt_flag) point=nobs nobs=nobs;
  dt_flag + 1;
end;
run;

proc append base=exist data=new_app;
run;

proc print data=exist noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;numdata	dt_flag
1	1
2	1
3	2
4	2
5	3
6	3
7	4
8	4
&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Jun 2020 14:00:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-data-to-a-table-and-increment-a-flag-on-the-resultant/m-p/652547#M195925</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-06-02T14:00:33Z</dc:date>
    </item>
    <item>
      <title>Re: Append data to a table and increment a flag on the resultant table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-data-to-a-table-and-increment-a-flag-on-the-resultant/m-p/652549#M195926</link>
      <description>&lt;P&gt;I think it can be done in one data step like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Table_A_Archive;
  modify Table_A_Archive end=done;
  DT_FLAG+1;
  replace;&lt;BR /&gt;  if done;&lt;BR /&gt;  DT_FLAG=1;
  do until(done2);
    set Table_A end=done2;
    output;
    end;
run;
    &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Jun 2020 14:09:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-data-to-a-table-and-increment-a-flag-on-the-resultant/m-p/652549#M195926</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-06-02T14:09:43Z</dc:date>
    </item>
    <item>
      <title>Re: Append data to a table and increment a flag on the resultant table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-data-to-a-table-and-increment-a-flag-on-the-resultant/m-p/652562#M195933</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/259982"&gt;@Sudhan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks for your response. But i need the DT_FLAG&amp;gt;=2, as this data will be used for a report.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Can you show exactly how the DT_Flag variable is used in your report?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might be surprised what could be done with your datetime variable without changing values of a variable.&lt;/P&gt;
&lt;P&gt;Or add the flag just before preparing the report. I find the idea of permanent data sets with values changing to be worrisome.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 14:30:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-data-to-a-table-and-increment-a-flag-on-the-resultant/m-p/652562#M195933</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-06-02T14:30:18Z</dc:date>
    </item>
    <item>
      <title>Re: Append data to a table and increment a flag on the resultant table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-data-to-a-table-and-increment-a-flag-on-the-resultant/m-p/652582#M195938</link>
      <description>&lt;P&gt;Kurt,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Two thoughts if I may:&lt;/P&gt;
&lt;P&gt;1) Wouldn't the MODIFY statement do an update "in place" without rewriting dataset?&lt;/P&gt;
&lt;P&gt;2) With increasing flag value for new data you will always have to find current maximum value to get the latest data instead just "where flag = 1".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 15:17:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-data-to-a-table-and-increment-a-flag-on-the-resultant/m-p/652582#M195938</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-06-02T15:17:33Z</dc:date>
    </item>
    <item>
      <title>Re: Append data to a table and increment a flag on the resultant table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-data-to-a-table-and-increment-a-flag-on-the-resultant/m-p/652596#M195942</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Kurt,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Two thoughts if I may:&lt;/P&gt;
&lt;P&gt;1) Wouldn't the MODIFY statement do an update "in place" without rewriting dataset?&lt;/P&gt;
&lt;P&gt;2) With increasing flag value for new data you will always have to find current maximum value to get the latest data instead just "where flag = 1".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you manipulate the flag variable in the existing data, you will always have to read/write the whole dataset. The increasing flag for new data means that you only have to read the last observation of the existing dataset, and increment that. So my code&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;reads the last observation of existing; will be very fast&lt;/LI&gt;
&lt;LI&gt;reads/writes the new data to set the flag&lt;/LI&gt;
&lt;LI&gt;reads/writes the new data during append&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;I don't know if you can use modify to do a pure append, where the existing data is not at least read as a whole.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 16:03:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-data-to-a-table-and-increment-a-flag-on-the-resultant/m-p/652596#M195942</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-06-02T16:03:59Z</dc:date>
    </item>
  </channel>
</rss>

