<?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 limiting in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Append-limiting/m-p/615503#M180039</link>
    <description>&lt;P&gt;Yes, its a macro that is running the iterations. Your suggestion makes sense. I just need to figure out how to create an iteration counter (which I believe you have called n_iterations).&amp;nbsp; Thanks&lt;/P&gt;</description>
    <pubDate>Mon, 06 Jan 2020 23:19:40 GMT</pubDate>
    <dc:creator>texasmfp</dc:creator>
    <dc:date>2020-01-06T23:19:40Z</dc:date>
    <item>
      <title>Append limiting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-limiting/m-p/615488#M180034</link>
      <description>&lt;P&gt;My program generates a single observation and, as the last step, appends this single observation to a results file (RESULTS1).&amp;nbsp; The results file starts empty.&amp;nbsp; I want to save every individual result but limit the size of the results file to 100,000 observations.&amp;nbsp; The observation generated by the 100,001th iteration would be automatically written to a new (empty) results file (Results2) again, up to 100,000 in size.&amp;nbsp; The 200,001th observation would go to another new results file (lets call it Results3) etc....So, in the end, if I run 350,000 iterations, I will end up with RESULTS1 (100,000 obs), RESULTS2 (100,000 obs), RESULTS3 (100,000 obs), RESULTS4 (50,000 obs)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Think of it as: I have five gallons of results that pour into a container one drop at a time, but I have pint sized containers so when one is full, the conveyor belt moves to next container and starts to fill it (and never miss a drop).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I limit the size of the results file, keep it, and then start a new one with a sequential name?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;append&lt;/SPAN&gt; base&lt;SPAN class="token operator"&gt;=RESULTS1&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=newestresult&lt;/SPAN&gt; force&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Jan 2020 22:08:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-limiting/m-p/615488#M180034</guid>
      <dc:creator>texasmfp</dc:creator>
      <dc:date>2020-01-06T22:08:44Z</dc:date>
    </item>
    <item>
      <title>Re: Append limiting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-limiting/m-p/615495#M180036</link>
      <description>&lt;P&gt;Are you saying your program will append one observation at a time, with the expectation that you will end up with multiple datasets of size 100,000? &amp;nbsp; That is the opposite of efficient.&amp;nbsp; It may be much better to think about how to append in larger batches that to worry immediately about dividing the result into datasets with fixed maximum size.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps you can tells us about the program that generates one result observation at a time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But as to your question.&amp;nbsp; Setting data set sizes to 100,000 is a much easier task.&amp;nbsp; Let's say you have data set HAVE with some large number of obs, but you know there are no more than 600,000 obs (i.e. you need no more than 6 WANT datasets).&amp;nbsp; Then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want1 want2 want3 want4 want5 want6;
  set have end=end_of_have nobs=n_have;
  if _n_&amp;lt;=100000 then output want1; else
  if _n_&amp;lt;=200000 then output want2; else
  if _n_&amp;lt;=300000 then output want3; else
  if _n_&amp;lt;=400000 then output want4; else
  if _n_&amp;lt;=500000 then output want5; else
  output want6;

  if end_of_have;
  if n_have &amp;lt;=500000 then call execute ('proc delete data=want6;run;');
  if n_have &amp;lt;=400000 then call execute ('proc delete data=want5;run;');
  if n_have &amp;lt;=300000 then call execute ('proc delete data=want4;run;');
  if n_have &amp;lt;=200000 then call execute ('proc delete data=want3;run;');
  if n_have &amp;lt;=100000 then call execute ('proc delete data=want2;run;');
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The above is a fairly straightforward program.&amp;nbsp; But as I said, appending one at a time - at the scale you contemplate - is an invitation to lots and lots of waiting.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2020 22:39:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-limiting/m-p/615495#M180036</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-01-06T22:39:22Z</dc:date>
    </item>
    <item>
      <title>Re: Append limiting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-limiting/m-p/615497#M180037</link>
      <description>Thanks.  Yes, I know that appending one at a time at 100,000+ results in waiting.  My testing shows that I can minimize the wait time by limiting the size of the appended dataset. &lt;BR /&gt;&lt;BR /&gt;However, your suggested program, which works beautifully, solves a problem I do not have.  I do not have a dataset named have that has been appended with 600,000 that I want to then split up into 6 pieces.  I never want "have" to be appended with more than 100,000.  I want to stop appending to have at the 100,000th iteration and start appending to a new file have2, then have3, etc at the append stage.&lt;BR /&gt;&lt;BR /&gt;The program that generates the single observation to be appended does not matter.  I am looking for a general solution that can apply to any program, not a specific one.</description>
      <pubDate>Mon, 06 Jan 2020 23:00:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-limiting/m-p/615497#M180037</guid>
      <dc:creator>texasmfp</dc:creator>
      <dc:date>2020-01-06T23:00:27Z</dc:date>
    </item>
    <item>
      <title>Re: Append limiting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-limiting/m-p/615502#M180038</link>
      <description>&lt;P&gt;Actually, some of the details of your program matter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Presumably, you are using macro language to iterate hundreds of thousands of times.&amp;nbsp; If that's incorrect, this approach may not apply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Within the macro program, you might have (and could certainly add) a macro variable to keep track of which iteration you are working on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And presumably you could add a small amount of code to this section:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc append base=RESULTS1 data=newestresult force;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Change it to look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc append base=RESULTS&amp;amp;result_set data=newestresult force;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then all you would need to do is to use your "number of iterations" macro variable.&amp;nbsp; Very early, outside the loop, add:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let result_set = 1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then just after PROC APPEND, add some logic to increment &amp;amp;RESULT_SET.&amp;nbsp; One possibility:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if %eval(&amp;amp;n_iterations / 100000 * 100000) = &amp;amp;n_iterations then 
%let result_set = %eval(&amp;amp;result_set + 1);&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2020 23:10:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-limiting/m-p/615502#M180038</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-01-06T23:10:51Z</dc:date>
    </item>
    <item>
      <title>Re: Append limiting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-limiting/m-p/615503#M180039</link>
      <description>&lt;P&gt;Yes, its a macro that is running the iterations. Your suggestion makes sense. I just need to figure out how to create an iteration counter (which I believe you have called n_iterations).&amp;nbsp; Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2020 23:19:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-limiting/m-p/615503#M180039</guid>
      <dc:creator>texasmfp</dc:creator>
      <dc:date>2020-01-06T23:19:40Z</dc:date>
    </item>
    <item>
      <title>Re: Append limiting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-limiting/m-p/615512#M180040</link>
      <description>shouldn't the statement logic be:&lt;BR /&gt;&lt;BR /&gt;%if %eval(&amp;amp;n_iterations /(&amp;amp;result_set * 100000) &amp;gt;1 then &lt;BR /&gt;%let result_set = %eval(&amp;amp;result_set + 1);</description>
      <pubDate>Tue, 07 Jan 2020 00:18:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-limiting/m-p/615512#M180040</guid>
      <dc:creator>texasmfp</dc:creator>
      <dc:date>2020-01-07T00:18:18Z</dc:date>
    </item>
    <item>
      <title>Re: Append limiting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-limiting/m-p/615518#M180042</link>
      <description>&lt;P&gt;Just keep count.&lt;/P&gt;
&lt;P&gt;Not sure how you are currently ending your iterations but here is one way to use two loops. One that just increments the target dataset name and the other counts how many iterations you have done for this set.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let set=1 ;
%let done=0;
%do %until(&amp;amp;done);
   %let inner_loop=1;
   %do %until(&amp;amp;done or &amp;amp;inner_loop&amp;gt;100000);
/* your processing here 
  including logic to set macro variable DONE=1 then time to stop looping 
*/
    proc append base=RESULTS&amp;amp;set data=newestresult force;
run;
    %let inner_loop=%eval(&amp;amp;inner_loop+1);
  %end; %* inner loop ;
  %let set=%eval(&amp;amp;set+1);
%end; %* outer loop;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Jan 2020 00:56:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-limiting/m-p/615518#M180042</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-07T00:56:39Z</dc:date>
    </item>
    <item>
      <title>Re: Append limiting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-limiting/m-p/615534#M180051</link>
      <description>&lt;P&gt;That logic would need to switch from %EVAL to %SYSEVALF.&amp;nbsp; The %EVAL function performs integer arithmatic, so it drops any remainders.&amp;nbsp; In fact, that's the reason why the original logic that I posted works:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if %eval(&amp;amp;n_iterations / 100000 * 100000) = &amp;amp;n_iterations then 
%let result_set = %eval(&amp;amp;result_set + 1); &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When &amp;amp;n_iterations is 100001, the division:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;amp;n_iterations / 100000&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;produces 1 as the result.&amp;nbsp; The remainder is dropped.&amp;nbsp; Multiplying by 100000 generates 100000 as the result, which is not equal to 100001.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are a few ways to get working logic out of this.&amp;nbsp; Just make sure the logic increments whenever &amp;amp;N_ITERATIONS is a multiple of 100000.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2020 03:47:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-limiting/m-p/615534#M180051</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-01-07T03:47:24Z</dc:date>
    </item>
    <item>
      <title>Re: Append limiting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-limiting/m-p/615553#M180055</link>
      <description>&lt;P&gt;I modified Astounding's suggestion and it works well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc append FORCE base=RESULT&amp;amp;result_set data=newestresult;
run; 

%if %eval(&amp;amp;i/(&amp;amp;result_set * 50000))&amp;gt;1 %then %let result_set = %eval(&amp;amp;result_set + 1);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I also added a subsequent macro to join all of the pieces:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let num_files = &amp;amp;result_set;

%macro join;                                                                                                                           

%do i=1 %to &amp;amp;num_files;
    %let padded_number = %sysfunc(putn(&amp;amp;i, 4.0));
    proc append base=full_set
                data=RESULT&amp;amp;padded_number;
    run;

	proc datasets lib=work nolist;
	delete RESULT&amp;amp;padded_number;
	quit;
	run;
 %end;

%mend join;                                                                                                                                  
                                                                                                                               
%join
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Tom, I didn't get to test yours, but I am sure it works similarly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Much thanks, once again, to SAS Communities!&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2020 06:26:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-limiting/m-p/615553#M180055</guid>
      <dc:creator>texasmfp</dc:creator>
      <dc:date>2020-01-07T06:26:15Z</dc:date>
    </item>
  </channel>
</rss>

