<?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: how to replace a output statement by a proc append in a if condition in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-replace-a-output-statement-by-a-proc-append-in-a-if/m-p/968790#M46001</link>
    <description>&lt;P&gt;I have tested my code and I have found that for the else condition, an output statement is fine.&amp;nbsp; But for the if condition, I do not need to replace the dataset but to append the data generated.&lt;BR /&gt;&lt;BR /&gt;So my question is how do we do that. How do we convert the condtion&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;if inlist and inbase then output dest2.&amp;amp;filename._Anonym;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if inlist and inbase then
do;
      proc append base=dest2.&amp;amp;filename._Anonym; data= what do we put here;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 11 Jun 2025 19:30:23 GMT</pubDate>
    <dc:creator>alepage</dc:creator>
    <dc:date>2025-06-11T19:30:23Z</dc:date>
    <item>
      <title>how to replace a output statement by a proc append in a if condition</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-replace-a-output-statement-by-a-proc-append-in-a-if/m-p/968781#M45998</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have tested the code below and it works well.&amp;nbsp; But I found that if we run the script again the anonymized dataset cannot be generated by append.&lt;/P&gt;
&lt;P&gt;How can we do that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the orginal code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dest1.&amp;amp;filename dest2.&amp;amp;filename._Anonym; /* Clean dataset and anonymized dataset */
   merge source4.&amp;amp;filename. (in=inbase)       /* premium dataset in the subfolder related to Data_Retention*/
   src1.&amp;amp;dsname. (in=inlist where=(filename = "&amp;amp;filename.")) ; /* The polices of the Master List and their location into the various premium dataset */
  by ORGNL_SAS_DS_ROW_NBR;
  if inlist and inbase then output dest2.&amp;amp;filename._Anonym;
  else if inbase then output dest1.&amp;amp;filename.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So, I need to replace the if inlist and inbase then do; proc append base=&lt;CODE class=" language-sas"&gt;dest2.&amp;amp;filename._Anonym data=??????;run;end;&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 18:27:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-replace-a-output-statement-by-a-proc-append-in-a-if/m-p/968781#M45998</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2025-06-11T18:27:43Z</dc:date>
    </item>
    <item>
      <title>Re: how to replace a output statement by a proc append in a if condition</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-replace-a-output-statement-by-a-proc-append-in-a-if/m-p/968782#M45999</link>
      <description>&lt;P&gt;The only way to conditionally call PROC APPEND (or any other PROC) is with an %IF statement (in a macro or in open code). You can't do that in a DATA step, that is invalid syntax. Something like this (pseudo code so you get the idea):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data octopus;
...
if condition1 then call symputx('macrovar',0);
else if condition2 then call symputx('macrovar',1);
run;
%if &amp;amp;macrovar %then %do;
proc append ... ;
run;
%end&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 18:44:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-replace-a-output-statement-by-a-proc-append-in-a-if/m-p/968782#M45999</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-06-11T18:44:56Z</dc:date>
    </item>
    <item>
      <title>Re: how to replace a output statement by a proc append in a if condition</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-replace-a-output-statement-by-a-proc-append-in-a-if/m-p/968783#M46000</link>
      <description>&lt;P&gt;I do not understand what your issue is.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your current data step is generating two output datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is it that you want to use PROC APPEND to do?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 18:37:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-replace-a-output-statement-by-a-proc-append-in-a-if/m-p/968783#M46000</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-06-11T18:37:59Z</dc:date>
    </item>
    <item>
      <title>Re: how to replace a output statement by a proc append in a if condition</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-replace-a-output-statement-by-a-proc-append-in-a-if/m-p/968790#M46001</link>
      <description>&lt;P&gt;I have tested my code and I have found that for the else condition, an output statement is fine.&amp;nbsp; But for the if condition, I do not need to replace the dataset but to append the data generated.&lt;BR /&gt;&lt;BR /&gt;So my question is how do we do that. How do we convert the condtion&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;if inlist and inbase then output dest2.&amp;amp;filename._Anonym;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if inlist and inbase then
do;
      proc append base=dest2.&amp;amp;filename._Anonym; data= what do we put here;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 19:30:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-replace-a-output-statement-by-a-proc-append-in-a-if/m-p/968790#M46001</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2025-06-11T19:30:23Z</dc:date>
    </item>
    <item>
      <title>Re: how to replace a output statement by a proc append in a if condition</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-replace-a-output-statement-by-a-proc-append-in-a-if/m-p/968793#M46002</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76331"&gt;@alepage&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have tested my code and I have found that for the else condition, an output statement is fine.&amp;nbsp; But for the if condition, I do not need to replace the dataset but to append the data generated.&lt;BR /&gt;&lt;BR /&gt;So my question is how do we do that. How do we convert the condtion&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;if inlist and inbase then output dest2.&amp;amp;filename._Anonym;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if inlist and inbase then
do;
      proc append base=dest2.&amp;amp;filename._Anonym; data= what do we put here;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You cannot put a PROC inside a DATA step. I already provided an earlier post in this thread explaining what to do instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This whole thread is the &lt;A href="https://en.wikipedia.org/wiki/XY_problem" target="_self"&gt;XY Problem&lt;/A&gt;. You have a "solution" that requires you to put PROC APPEND into a DATA step, but you are having trouble doing it. You haven't told us the problem that this allegedly solves, and it would be extremely helpful if you backed up and explain the entire problem you are trying to solve, rather than focusing on your solution of putting a PROC into a DATA step. Please note that backing up and explain the entire problem, rather than focusing on your desired solution, is a far superior approach that can produce much better solutions, involving less code and less confusion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if we're going to move forward, we first have to move backward and understand what the problem is that you are trying to solve with a PROC in a DATA step.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 20:36:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-replace-a-output-statement-by-a-proc-append-in-a-if/m-p/968793#M46002</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-06-11T20:36:22Z</dc:date>
    </item>
    <item>
      <title>Re: how to replace a output statement by a proc append in a if condition</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-replace-a-output-statement-by-a-proc-append-in-a-if/m-p/968801#M46003</link>
      <description>&lt;P&gt;Two general solutions.&lt;/P&gt;
&lt;P&gt;Leave your data step essentially the same, but &lt;STRONG&gt;write the "APPEND" records to a temporary dataset.&amp;nbsp; Then use a second step running PROC APPEND to add&lt;/STRONG&gt;&amp;nbsp;that temporary dataset to the permanent dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Write the matching records to a dataset, let's call it BOTH.&amp;nbsp; Write the unmatched BASE records to another temporary dataset, let's call it TEMP_BASE.&amp;nbsp; Then append that temporary dataset to some existing (or not existing dataset since PROC APPEND does not care) permanent dataset, let's call that PERMANENT_BASE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data BOTH TEMP_BASE ;
   merge  BASE (in=inbase) 
          LIST (in=inlist where=(filename = "MYFILENAME"))
  ;
  by BYVAR ;
  if inlist and inbase then output BOTH;
  else if inbase then output TEMP_BASE;
  else /* Ignore the LIST_ONLY records */ ;
run;

proc append data=TEMP_BASE base=PERMANENT_BASE;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;NOTE: Once you know what code you want to generate you can start replacing some of the code with macro variable references.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;The other way is to use a MODIFY statement&lt;/STRONG&gt; which will allow you to use the APPEND statement to append observations to a dataset in a single data step.&amp;nbsp; You can also use an OUTPUT statement to write those other observations to some other output dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is hard to tell from your dataset names and your descriptions so far exactly what you are trying to do.&amp;nbsp; But perhaps it is something like this:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have two input datasets named BASE and LIST and you want to combine them to generate observations that are either appended to PERMNENT or written to a brand NEW dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data permanent new ;
   if 0 then modify permanent;
   merge base(in=inbase) list(in=inlist);
   by keyvar;
   if inbase and inlist then output new;
   else if inbase then append;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But somehow I doubt it.&amp;nbsp; More likely you will want to use the KEY= option on the MODIFY statement to get it to work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Providing a simple example of the inputs with just enough observations to demonstrate the different possible situation will make it much easier to design and test different solutions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jun 2025 02:22:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-replace-a-output-statement-by-a-proc-append-in-a-if/m-p/968801#M46003</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-06-12T02:22:59Z</dc:date>
    </item>
  </channel>
</rss>

