<?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: Stacking multiple datasets within a Macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Stacking-multiple-datasets-within-a-Macro/m-p/146651#M29173</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;@rw9&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;A href="http://www.pharmasug.org/proceedings/2012/TA/PharmaSUG-2012-TA05.pdf" title="http://www.pharmasug.org/proceedings/2012/TA/PharmaSUG-2012-TA05.pdf"&gt;http://www.pharmasug.org/proceedings/2012/TA/PharmaSUG-2012-TA05.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Couldn't find anything in the docs in my 2 min search &lt;img id="smileysad" class="emoticon emoticon-smileysad" src="https://communities.sas.com/i/smilies/16x16_smiley-sad.png" alt="Smiley Sad" title="Smiley Sad" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;@dangIT&lt;/P&gt;&lt;P&gt;I would add a check at the beginning of the macro&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ie if the output dataset is going to be called feb_wk01, and the data has that info in the data set as well the following may work.&lt;/P&gt;&lt;P&gt;You can change the WHERE criteria to match your data;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;delete * from master_table where week="feb_wk01";&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 18 Jun 2014 15:07:39 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2014-06-18T15:07:39Z</dc:date>
    <item>
      <title>Stacking multiple datasets within a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stacking-multiple-datasets-within-a-Macro/m-p/146642#M29164</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a macro that run's a 'report' on in the structure of:&lt;/P&gt;&lt;P&gt;%macro Report(Weekname,LYwk,TYwk) ;&lt;/P&gt;&lt;P&gt;which creates an output dataset named by the Weekname...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;An example of a few weeks of the above macro (I have about to run):&lt;/P&gt;&lt;P&gt;%Report(Feb_wk02,201302,201402) ; (output dataset = Feb_wk01)&lt;/P&gt;&lt;P&gt;%Report(Feb_wk04,201304,201404) ; (output dataset = Feb_wk04)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I would like to do is create a macro to stack all of these output datasets into one Master table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know I can do it the manual method of :&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Data Master; Set (name of all the datasets) ; run ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But i'm wondering if there's a more automated method.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance for your help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jun 2014 14:04:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stacking-multiple-datasets-within-a-Macro/m-p/146642#M29164</guid>
      <dc:creator>DangIT</dc:creator>
      <dc:date>2014-06-18T14:04:19Z</dc:date>
    </item>
    <item>
      <title>Re: Stacking multiple datasets within a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stacking-multiple-datasets-within-a-Macro/m-p/146643#M29165</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You could use the SASHELP.VTABLE, and then generate the code directly from there - e.g:&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set sashelp.vtable (where=(libname="your libname")) end=last;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if _n_=1 then call execute('data total; set ');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call execute(memname||" ");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if last then call execute('; run;');&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will generate a dataset with a set and then every dataset within the library.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jun 2014 14:23:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stacking-multiple-datasets-within-a-Macro/m-p/146643#M29165</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-06-18T14:23:34Z</dc:date>
    </item>
    <item>
      <title>Re: Stacking multiple datasets within a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stacking-multiple-datasets-within-a-Macro/m-p/146644#M29166</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;%macro allsets;&lt;/P&gt;&lt;P&gt;data master;&lt;/P&gt;&lt;P&gt;set &lt;/P&gt;&lt;P&gt;%do i=1 %to 10;&lt;/P&gt;&lt;P&gt;have&amp;amp;i&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend allsets;&lt;/P&gt;&lt;P&gt;%allsets&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jun 2014 14:27:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stacking-multiple-datasets-within-a-Macro/m-p/146644#M29166</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2014-06-18T14:27:50Z</dc:date>
    </item>
    <item>
      <title>Re: Stacking multiple datasets within a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stacking-multiple-datasets-within-a-Macro/m-p/146645#M29167</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you, i will look into this method, can the above code be modified to include a prefix of the tables rather than all the datasets in the library?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jun 2014 14:28:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stacking-multiple-datasets-within-a-Macro/m-p/146645#M29167</guid>
      <dc:creator>DangIT</dc:creator>
      <dc:date>2014-06-18T14:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: Stacking multiple datasets within a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stacking-multiple-datasets-within-a-Macro/m-p/146646#M29168</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can also use shorthand notation or add a proc append to the end of your main macro.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;APPEND @ end of current macro&lt;/P&gt;&lt;P&gt;proc append base=data_final data=feb_wk01;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Short hand using the colon short hand notation, note the colon at the end of the jan_wk: , which tells SAS to include all datasets that start with the name jan_wk.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data data_final;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set jan_wk: feb_wk: mar_wk: ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jun 2014 14:31:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stacking-multiple-datasets-within-a-Macro/m-p/146646#M29168</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-06-18T14:31:22Z</dc:date>
    </item>
    <item>
      <title>Re: Stacking multiple datasets within a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stacking-multiple-datasets-within-a-Macro/m-p/146647#M29169</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, sure.&amp;nbsp; Whatever you can do in a dataset you can do here so assuming I prefix with "AAA":&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set sashelp.vtable (where=(libname="your libname" and susbtr(memname,1,3)="AAA")) end=last;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if _n_=1 then call execute('data total; set ');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call execute(memname||" ");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if last then call execute('; run;');&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jun 2014 14:32:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stacking-multiple-datasets-within-a-Macro/m-p/146647#M29169</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-06-18T14:32:06Z</dc:date>
    </item>
    <item>
      <title>Re: Stacking multiple datasets within a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stacking-multiple-datasets-within-a-Macro/m-p/146648#M29170</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Interesting, I had seen that wildcard-esque type before, would you have a link to the help on that?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jun 2014 14:33:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stacking-multiple-datasets-within-a-Macro/m-p/146648#M29170</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-06-18T14:33:27Z</dc:date>
    </item>
    <item>
      <title>Re: Stacking multiple datasets within a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stacking-multiple-datasets-within-a-Macro/m-p/146649#M29171</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I ended up using the Append approach, it was much simpler solution going forward.&lt;/P&gt;&lt;P&gt;But i will have to include some controls to ensure if the macro that week's table does not append to the master twice if it's re-run for some reason.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for all your help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jun 2014 14:45:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stacking-multiple-datasets-within-a-Macro/m-p/146649#M29171</guid>
      <dc:creator>DangIT</dc:creator>
      <dc:date>2014-06-18T14:45:59Z</dc:date>
    </item>
    <item>
      <title>Re: Stacking multiple datasets within a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stacking-multiple-datasets-within-a-Macro/m-p/146650#M29172</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Reeza, any thoughts on how I can ensure that if the macro is run again, that the previous data is removed and only the latest data is appended to the master table?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jun 2014 14:52:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stacking-multiple-datasets-within-a-Macro/m-p/146650#M29172</guid>
      <dc:creator>DangIT</dc:creator>
      <dc:date>2014-06-18T14:52:56Z</dc:date>
    </item>
    <item>
      <title>Re: Stacking multiple datasets within a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stacking-multiple-datasets-within-a-Macro/m-p/146651#M29173</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;@rw9&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;A href="http://www.pharmasug.org/proceedings/2012/TA/PharmaSUG-2012-TA05.pdf" title="http://www.pharmasug.org/proceedings/2012/TA/PharmaSUG-2012-TA05.pdf"&gt;http://www.pharmasug.org/proceedings/2012/TA/PharmaSUG-2012-TA05.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Couldn't find anything in the docs in my 2 min search &lt;img id="smileysad" class="emoticon emoticon-smileysad" src="https://communities.sas.com/i/smilies/16x16_smiley-sad.png" alt="Smiley Sad" title="Smiley Sad" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;@dangIT&lt;/P&gt;&lt;P&gt;I would add a check at the beginning of the macro&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ie if the output dataset is going to be called feb_wk01, and the data has that info in the data set as well the following may work.&lt;/P&gt;&lt;P&gt;You can change the WHERE criteria to match your data;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;delete * from master_table where week="feb_wk01";&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jun 2014 15:07:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stacking-multiple-datasets-within-a-Macro/m-p/146651#M29173</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-06-18T15:07:39Z</dc:date>
    </item>
    <item>
      <title>Re: Stacking multiple datasets within a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stacking-multiple-datasets-within-a-Macro/m-p/146652#M29174</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Search for DATA SET LISTS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="active_link" href="http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a003040446.htm" title="http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a003040446.htm"&gt;http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a003040446.htm&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jun 2014 15:25:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stacking-multiple-datasets-within-a-Macro/m-p/146652#M29174</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-06-18T15:25:02Z</dc:date>
    </item>
  </channel>
</rss>

