<?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 do until: struggling to add observation to the same dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/do-until-struggling-to-add-observation-to-the-same-dataset/m-p/807511#M318383</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am running a do until condition and I want the output at the end of each iteration to be added to the same dataset ie.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro ..;&lt;/P&gt;
&lt;P&gt;%do %until ();&lt;/P&gt;
&lt;P&gt;more processing....&lt;/P&gt;
&lt;P&gt;data x y;&lt;/P&gt;
&lt;P&gt;if ...output x;&lt;/P&gt;
&lt;P&gt;else output y;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;%mend.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I am looking to do is at the end of each do until iteration, one dataset that meets the condition is generated and I want to keep adding records to it as I go through the do loop in each iteration. How is this possible?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 12 Apr 2022 23:17:30 GMT</pubDate>
    <dc:creator>Tommer</dc:creator>
    <dc:date>2022-04-12T23:17:30Z</dc:date>
    <item>
      <title>do until: struggling to add observation to the same dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-until-struggling-to-add-observation-to-the-same-dataset/m-p/807511#M318383</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am running a do until condition and I want the output at the end of each iteration to be added to the same dataset ie.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro ..;&lt;/P&gt;
&lt;P&gt;%do %until ();&lt;/P&gt;
&lt;P&gt;more processing....&lt;/P&gt;
&lt;P&gt;data x y;&lt;/P&gt;
&lt;P&gt;if ...output x;&lt;/P&gt;
&lt;P&gt;else output y;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;%mend.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I am looking to do is at the end of each do until iteration, one dataset that meets the condition is generated and I want to keep adding records to it as I go through the do loop in each iteration. How is this possible?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 23:17:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-until-struggling-to-add-observation-to-the-same-dataset/m-p/807511#M318383</guid>
      <dc:creator>Tommer</dc:creator>
      <dc:date>2022-04-12T23:17:30Z</dc:date>
    </item>
    <item>
      <title>Re: do until: struggling to add observation to the same dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-until-struggling-to-add-observation-to-the-same-dataset/m-p/807513#M318385</link>
      <description>&lt;P&gt;Each loop iteration is going to replace both data sets X and Y as currently written. You may need to decide on desired data set names for the final result. Then us Proc Append to add x and y to the final set within each loop.&lt;/P&gt;
&lt;P&gt;Something conceptually like:&lt;/P&gt;
&lt;PRE&gt;%macro ..;
   %do %until ();
   /*more processing....*/
      data x y;
         if ...output x;
         else output y;
      run;

      proc append base=finalx data=x;
      run;
      Proc append base=finaly data=y;
      run;
   %end;
%mend.&lt;/PRE&gt;
&lt;P&gt;Note, your current data steps would not have generated anything as there is nothing providing values that I can see, such as a SET statement.&lt;/P&gt;
&lt;P&gt;This assumes that the variables in the X and Y data sets will be the same name, type and length each time. Otherwise you &lt;STRONG&gt;really&lt;/STRONG&gt; need to provide examples as appending random stuff runs into issues of variable type compatibility and lengths of character variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is an extremely good idea in macro programming to explicitly end every data step or procedure properly with Run or Quit statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You really should provide some example data and what you expect the output to look like.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2022 14:07:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-until-struggling-to-add-observation-to-the-same-dataset/m-p/807513#M318385</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-04-13T14:07:11Z</dc:date>
    </item>
    <item>
      <title>Re: do until: struggling to add observation to the same dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-until-struggling-to-add-observation-to-the-same-dataset/m-p/807515#M318387</link>
      <description>This worked!! I used proc append. I think I need to work on my macro logic better but what i was looking for from this query worked! Thank you so so much!</description>
      <pubDate>Tue, 12 Apr 2022 23:41:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-until-struggling-to-add-observation-to-the-same-dataset/m-p/807515#M318387</guid>
      <dc:creator>Tommer</dc:creator>
      <dc:date>2022-04-12T23:41:52Z</dc:date>
    </item>
  </channel>
</rss>

