<?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 Conditionally judgement whether append a new data or output in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-judgement-whether-append-a-new-data-or-output/m-p/423499#M280962</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a number of daily trading data set, which are named as t20161201, t20161202, etc.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to compute a cumulative trading volume (e.g. volume + size), and once the cumulative volume exceeds a specified threshold, then stop the computing and output this single obs (since I want to know how long to&amp;nbsp;get this volume).&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is that sometimes the threshold is very large, and it may take several days for a stock to reach this trading volume. So I have to judge whether I need to append next day's data&amp;nbsp; to compute the volume until it meets the threshold.&amp;nbsp;&lt;/P&gt;&lt;P&gt;One possible logic is to combine these daily data set together and compute the volume directly, but the size of these data set could be very large ( 4g per data set), so it may be inefficient to compute it in this way.&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this case, I have to judge whether I can get the volume within one day, if not, then I need to append next day' data and compute again, then I have to judge again and compute again...until the volume meets the threshold.&lt;/P&gt;&lt;P&gt;I am struggling to write the code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any helps is very appreciated!!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 25 Dec 2017 08:36:10 GMT</pubDate>
    <dc:creator>cczzzl</dc:creator>
    <dc:date>2017-12-25T08:36:10Z</dc:date>
    <item>
      <title>Conditionally judgement whether append a new data or output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-judgement-whether-append-a-new-data-or-output/m-p/423499#M280962</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a number of daily trading data set, which are named as t20161201, t20161202, etc.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to compute a cumulative trading volume (e.g. volume + size), and once the cumulative volume exceeds a specified threshold, then stop the computing and output this single obs (since I want to know how long to&amp;nbsp;get this volume).&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is that sometimes the threshold is very large, and it may take several days for a stock to reach this trading volume. So I have to judge whether I need to append next day's data&amp;nbsp; to compute the volume until it meets the threshold.&amp;nbsp;&lt;/P&gt;&lt;P&gt;One possible logic is to combine these daily data set together and compute the volume directly, but the size of these data set could be very large ( 4g per data set), so it may be inefficient to compute it in this way.&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this case, I have to judge whether I can get the volume within one day, if not, then I need to append next day' data and compute again, then I have to judge again and compute again...until the volume meets the threshold.&lt;/P&gt;&lt;P&gt;I am struggling to write the code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any helps is very appreciated!!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Dec 2017 08:36:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-judgement-whether-append-a-new-data-or-output/m-p/423499#M280962</guid>
      <dc:creator>cczzzl</dc:creator>
      <dc:date>2017-12-25T08:36:10Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally judgement whether append a new data or output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-judgement-whether-append-a-new-data-or-output/m-p/423502#M280963</link>
      <description>&lt;P&gt;Do you know the "volume + size" of each of your datasets?&lt;/P&gt;
&lt;P&gt;I assume that appending two datasets will result in the sum of those two.&lt;/P&gt;
&lt;P&gt;You can simulate the appending result manually&amp;nbsp; and decide what period of datasets&lt;/P&gt;
&lt;P&gt;can be combined.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Dec 2017 09:53:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-judgement-whether-append-a-new-data-or-output/m-p/423502#M280963</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-12-25T09:53:40Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally judgement whether append a new data or output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-judgement-whether-append-a-new-data-or-output/m-p/423505#M280964</link>
      <description>Sorry I didn't clarify the question.&lt;BR /&gt;The size is a variable in these data set.&lt;BR /&gt;The volume is a new variable computed based on the size.&lt;BR /&gt;&lt;BR /&gt;My goal is trying to decide automatically by program otherwise it will be very time-consuming.</description>
      <pubDate>Mon, 25 Dec 2017 11:08:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-judgement-whether-append-a-new-data-or-output/m-p/423505#M280964</guid>
      <dc:creator>cczzzl</dc:creator>
      <dc:date>2017-12-25T11:08:12Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally judgement whether append a new data or output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-judgement-whether-append-a-new-data-or-output/m-p/423512#M280965</link>
      <description>&lt;P&gt;You can use a macro program, compute the volume of one day dataset.&lt;/P&gt;
&lt;P&gt;Keep few global macro variables:&amp;nbsp; dataset volume, accumulated volume, max volume, flag to check is max reached.&lt;/P&gt;
&lt;P&gt;If &amp;lt;accumulated&amp;gt; + &amp;lt;new volume&amp;gt; LE &amp;lt;max volume&amp;gt; then append data set to the accumulated dataset.&lt;/P&gt;
&lt;P&gt;Skilton of program should look like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let accumulated_volume = 0;
%let max_volume = ...;
%global new_volume;
%let flag = 0;
proc datasets lib=&amp;lt;library&amp;gt;; delete acc_dataset; quit;

%macro check(dsname);
  %if flag ne 0 %then %goto exit;
   data _null_;
       set &amp;amp;dsname end=eof;
           ... compute volume by size...
          if eof then call sympy('new_volume', &amp;lt;computed volume&amp;gt;);
   run;
   %if %eval(&amp;amp;accumulated_volume + &amp;amp;new_volume) LE &amp;amp;max_volume
   %then %do;
          %let accumulated_volume = %eval(&amp;amp;accumulated_volume + &amp;amp;new_volume);
          proc append base=acc_dataset data=&amp;amp;dsn; run;
    %end;
   %else %do;
       %put Max Volume reached;
       %let flag = 1;
   %end;&lt;BR /&gt;%exit:       /* &amp;lt;&amp;lt;&amp;lt; line added */
%mend check;
%check(&amp;lt;day1 dataset&amp;gt;);&lt;BR /&gt;%check(&amp;lt;day2 dataset&amp;gt;0;&lt;BR /&gt;...&lt;BR /&gt;%check(&amp;lt;last day dataset&amp;gt;);
       &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Dec 2017 13:05:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-judgement-whether-append-a-new-data-or-output/m-p/423512#M280965</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-12-25T13:05:35Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally judgement whether append a new data or output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-judgement-whether-append-a-new-data-or-output/m-p/423514#M280966</link>
      <description>&lt;P&gt;From what you describe, this should be an easy problem.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set t20161201 t20161202 t20161203 t20161204 t230161205;&lt;/P&gt;
&lt;P&gt;volume +size;&lt;/P&gt;
&lt;P&gt;if volume &amp;gt; 100000 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; stop;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You decide how many data sets you want to add to the SET statement, and what the cutoff should be.&amp;nbsp; But SAS doesn't need to read any extra observations with this structure to the program.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Dec 2017 14:42:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-judgement-whether-append-a-new-data-or-output/m-p/423514#M280966</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-12-25T14:42:59Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally judgement whether append a new data or output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-judgement-whether-append-a-new-data-or-output/m-p/423650#M280967</link>
      <description>&lt;P&gt;Make a list of ALL the daily datasets,&amp;nbsp;and SET them with "open=defer" which tells sas to reused the same buffer for each dataset, rather than create a buffer&amp;nbsp; for each. Then once the threshold has been reached, output and stop.&amp;nbsp;&amp;nbsp; No need to conditionally add datasets.&amp;nbsp; It's easier to conditionally stop reading.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This example reads all the December 2012 datasets, which you have named very usefully, allowing use of the name prefix for all the daily datasets of interest.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set t 201612: open=defer;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; volume+size;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if volume&amp;gt;=threshold;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; stop;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Dec 2017 22:57:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-judgement-whether-append-a-new-data-or-output/m-p/423650#M280967</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-12-26T22:57:27Z</dc:date>
    </item>
  </channel>
</rss>

