<?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 data inside macro loop (with output statement) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/append-data-inside-macro-loop-with-output-statement/m-p/232058#M42286</link>
    <description>&lt;P&gt;Since your macro replaces the two data sets each time it runs, you will need some other data sets to hold the complete versions from all iterations.&amp;nbsp; You could, for example, add this to the end of your macro definition (before %mend):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc append data=combo_meds_split1 base=all_split1;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;proc append data=combo_meds_split2 base=all_split2;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that this always adds and never replaces.&amp;nbsp; So if you run your iterations today, you will be adding to what you created when you ran the program yesterday (if you permanently save the outputs).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck.&lt;/P&gt;</description>
    <pubDate>Wed, 28 Oct 2015 16:22:14 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2015-10-28T16:22:14Z</dc:date>
    <item>
      <title>append data inside macro loop (with output statement)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/append-data-inside-macro-loop-with-output-statement/m-p/232050#M42283</link>
      <description>&lt;P&gt;Hello all:&lt;/P&gt;
&lt;P&gt;I am trying to output obs to two different datasets inside a macro loop.&amp;nbsp; Only the obs from the last iteration of the macro are saved to my two datasets.&amp;nbsp; I am using this code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro split (combo, drug1, class1, drug2, class2);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data combo_meds_split1 combo_meds_split2;&lt;/P&gt;
&lt;P&gt;set combo_meds;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if drugnamewithoutdose="&amp;amp;combo" then do;&lt;/P&gt;
&lt;P&gt;drugnamewithoutdose="&amp;amp;drug1"; drugclasscode="&amp;amp;class1"; output combo_meds_split1;&lt;/P&gt;
&lt;P&gt;drugnamewithoutdose="&amp;amp;drug2"; drugclasscode="&amp;amp;class2"; output combo_meds_split2;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;%mend split;&lt;/P&gt;
&lt;P&gt;%split (ALISKIREN/HYDROCHLOROTHIAZIDE, ALISKIREN, CV806, HYDROCHLOROTHIAZIDE, CV701)&lt;/P&gt;
&lt;P&gt;%split (AMLODIPINE/BENAZEPRIL, AMLODIPINE, CV200, BENAZEPRIL, CV800)&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any ideas how to get all obs for all iterations of the macro to write to the two datasets?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks so much,&lt;/P&gt;
&lt;P&gt;Kelly&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Oct 2015 16:05:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/append-data-inside-macro-loop-with-output-statement/m-p/232050#M42283</guid>
      <dc:creator>kstolzmann</dc:creator>
      <dc:date>2015-10-28T16:05:50Z</dc:date>
    </item>
    <item>
      <title>Re: append data inside macro loop (with output statement)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/append-data-inside-macro-loop-with-output-statement/m-p/232058#M42286</link>
      <description>&lt;P&gt;Since your macro replaces the two data sets each time it runs, you will need some other data sets to hold the complete versions from all iterations.&amp;nbsp; You could, for example, add this to the end of your macro definition (before %mend):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc append data=combo_meds_split1 base=all_split1;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;proc append data=combo_meds_split2 base=all_split2;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that this always adds and never replaces.&amp;nbsp; So if you run your iterations today, you will be adding to what you created when you ran the program yesterday (if you permanently save the outputs).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Oct 2015 16:22:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/append-data-inside-macro-loop-with-output-statement/m-p/232058#M42286</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-10-28T16:22:14Z</dc:date>
    </item>
    <item>
      <title>Re: append data inside macro loop (with output statement)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/append-data-inside-macro-loop-with-output-statement/m-p/232092#M42288</link>
      <description>&lt;P&gt;You could use the values of your parameters to name the output sets such as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;drugnamewithoutdose="&amp;amp;drug1"; drugclasscode="&amp;amp;class1"; output combo_meds_split1&amp;amp;drug1.&amp;amp;class1;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Oct 2015 17:55:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/append-data-inside-macro-loop-with-output-statement/m-p/232092#M42288</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-10-28T17:55:21Z</dc:date>
    </item>
    <item>
      <title>Re: append data inside macro loop (with output statement)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/append-data-inside-macro-loop-with-output-statement/m-p/232111#M42293</link>
      <description>&lt;P&gt;Thank you!&amp;nbsp; The append inside the macro works perfectly.&amp;nbsp; I thought about making each&amp;nbsp;iteration a separate dataset (inside the macro) but the append option is nice because it saves a step of having to set all of the the resulting datasets at the end.&amp;nbsp; Thanks again, all!&lt;/P&gt;</description>
      <pubDate>Wed, 28 Oct 2015 19:15:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/append-data-inside-macro-loop-with-output-statement/m-p/232111#M42293</guid>
      <dc:creator>kstolzmann</dc:creator>
      <dc:date>2015-10-28T19:15:02Z</dc:date>
    </item>
  </channel>
</rss>

