<?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 a new dataset to a existing dataset conditionally in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Append-a-new-dataset-to-a-existing-dataset-conditionally/m-p/421147#M280693</link>
    <description>I thought about it as well.&lt;BR /&gt;But the daily data are quite large ( up to 4G per dataset), so it may be slower using this logic.&lt;BR /&gt;Anyway, thank you very much!</description>
    <pubDate>Thu, 14 Dec 2017 11:20:03 GMT</pubDate>
    <dc:creator>cczzzl</dc:creator>
    <dc:date>2017-12-14T11:20:03Z</dc:date>
    <item>
      <title>Append a new dataset to a existing dataset conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-a-new-dataset-to-a-existing-dataset-conditionally/m-p/420784#M280690</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset with a single obs, which is like:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="微信截图_20171213213954.png" style="width: 181px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/17190iE12B73103836C17E/image-dimensions/181x52?v=v2" width="181" height="52" role="button" title="微信截图_20171213213954.png" alt="微信截图_20171213213954.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The num here is computed cumulatively based on another column ( sum of the value in that column)&lt;/P&gt;&lt;P&gt;The condition defined as whether the num is smaller than a specific value.&lt;/P&gt;&lt;P&gt;If yes, then I need to append a new dataset to this dataset and&amp;nbsp;compute the cumulative value (including the "num" here) again until it meets the condition, then I can extract this obs into a dataset with a single value.&lt;/P&gt;&lt;P&gt;If not, I just want to keep the dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code I use:&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;set have;&lt;/P&gt;&lt;P&gt;if value &amp;lt;= 10000000 then do;&lt;/P&gt;&lt;P&gt;set new.have;&lt;/P&gt;&lt;P&gt;by name;&lt;/P&gt;&lt;P&gt;if first.obs then do;&lt;/P&gt;&lt;P&gt;value&amp;nbsp;= value;end;&lt;/P&gt;&lt;P&gt;value + value1;&lt;/P&gt;&lt;P&gt;else if value &amp;gt; 10000000 then output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am quite new to SAS, so any helps are much appreciated!&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much!&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 13:59:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-a-new-dataset-to-a-existing-dataset-conditionally/m-p/420784#M280690</guid>
      <dc:creator>cczzzl</dc:creator>
      <dc:date>2017-12-13T13:59:24Z</dc:date>
    </item>
    <item>
      <title>Re: Append a new dataset to a existing dataset conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-a-new-dataset-to-a-existing-dataset-conditionally/m-p/420815#M280691</link>
      <description>&lt;P&gt;Let's say you have a second data set named MORE_VALUES, that contains a variable named VALUE1.&amp;nbsp; You could approach the problem in this way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;if value &amp;lt;= 10000000 then do until (value &amp;gt; 10000000);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set more_values;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; value + value1;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;output;&lt;/P&gt;
&lt;P&gt;stop;&lt;/P&gt;
&lt;P&gt;keep name value;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 14:56:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-a-new-dataset-to-a-existing-dataset-conditionally/m-p/420815#M280691</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-12-13T14:56:13Z</dc:date>
    </item>
    <item>
      <title>Re: Append a new dataset to a existing dataset conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-a-new-dataset-to-a-existing-dataset-conditionally/m-p/420863#M280692</link>
      <description>&lt;P&gt;I'm going to suggest a slightly different approach that isn't going to involve creating what I suspect would end up being a maintenance nightmare if you have to do this repetitively:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Combine multiple data sets&lt;/P&gt;
&lt;P&gt;Calculate&amp;nbsp;a rolling&amp;nbsp;cumulative for all of the data.&lt;/P&gt;
&lt;P&gt;Select the data where the value of the cumulative value is less than or equal to your threshold value.&lt;/P&gt;
&lt;PRE&gt;/* create two datasets just to have something to demostrate*/
data work.one;
   do x= 1 to 20;
     output;
   end;
run;

data work.two;
   do x= 5 to 25;
      output;
   end;
run;

data work.both;
   set work.one
       work.two
   ;
   retain cumx;
   cumx = sum(cumx,x);
   /* if the threshold value of the cumulative variable is 305*/
   output;
   if cumx ge 305 then stop;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may have to work on additional logic if you want the data where the cumulative value is only less than the threshold but doesn't exceed it.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 15:58:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-a-new-dataset-to-a-existing-dataset-conditionally/m-p/420863#M280692</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-12-13T15:58:00Z</dc:date>
    </item>
    <item>
      <title>Re: Append a new dataset to a existing dataset conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-a-new-dataset-to-a-existing-dataset-conditionally/m-p/421147#M280693</link>
      <description>I thought about it as well.&lt;BR /&gt;But the daily data are quite large ( up to 4G per dataset), so it may be slower using this logic.&lt;BR /&gt;Anyway, thank you very much!</description>
      <pubDate>Thu, 14 Dec 2017 11:20:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-a-new-dataset-to-a-existing-dataset-conditionally/m-p/421147#M280693</guid>
      <dc:creator>cczzzl</dc:creator>
      <dc:date>2017-12-14T11:20:03Z</dc:date>
    </item>
    <item>
      <title>Re: Append a new dataset to a existing dataset conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-a-new-dataset-to-a-existing-dataset-conditionally/m-p/421148#M280694</link>
      <description>The thing the new data set is daily data, which means I have a lot of daily data not just one to append the existing data. So I need repeat the procedure until the condition is satisfied.</description>
      <pubDate>Thu, 14 Dec 2017 11:22:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-a-new-dataset-to-a-existing-dataset-conditionally/m-p/421148#M280694</guid>
      <dc:creator>cczzzl</dc:creator>
      <dc:date>2017-12-14T11:22:26Z</dc:date>
    </item>
  </channel>
</rss>

