<?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 Combining multiple datasets using a loop in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Combining-multiple-datasets-using-a-loop/m-p/214387#M11578</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;A quick question.&lt;/P&gt;&lt;P&gt;I have several datasets (HR1, HR2, HR3,.....HR 20)&lt;/P&gt;&lt;P&gt;I need to combine a number of these tables using (data..set) according to certain criteria, since this is a repetitive task I chose to build a macro like this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;/P&gt;&lt;P class="p2"&gt;&lt;SPAN class="s1"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/SPAN&gt; repeat_set(n=);&lt;/P&gt;&lt;P class="p2"&gt;&lt;SPAN class="s2"&gt;%do&lt;/SPAN&gt; var=&lt;SPAN class="s3"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN class="s2"&gt;%to&lt;/SPAN&gt; &amp;amp;n; &lt;/P&gt;&lt;P class="p2"&gt;Data j;&lt;/P&gt;&lt;P class="p2" style="font-size: 13.3333330154419px;"&gt;if &amp;amp;var=&lt;SPAN class="s3"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt; then do;&lt;/P&gt;&lt;P class="p2" style="font-size: 13.3333330154419px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set HR&amp;amp;var;&lt;/P&gt;&lt;P class="p2" style="font-size: 13.3333330154419px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P class="p2"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;else &lt;/SPAN&gt;if &amp;amp;var gt &lt;SPAN class="s3"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt; then do;&lt;/P&gt;&lt;P class="p2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set j HR&amp;amp;var;&lt;/P&gt;&lt;P class="p2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P class="p2"&gt;&lt;/P&gt;&lt;P class="p2"&gt;run;&lt;/P&gt;&lt;P class="p3"&gt;%end&lt;SPAN class="s4"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p4"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;SPAN class="s4"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;/P&gt;&lt;P class="p2"&gt;&lt;/P&gt;&lt;P class="p2"&gt;&lt;/P&gt;&lt;P class="p2"&gt;The reason why I am doing this is that the new dataset 'J' dose not exist from the beginning, so while looping, the idea is when the code takes the first HR set (HR1) it will create 'j' using the following:&lt;/P&gt;&lt;P class="p2"&gt;data j;&lt;/P&gt;&lt;P class="p2"&gt;set HR1;&lt;/P&gt;&lt;P class="p2"&gt;run;&lt;/P&gt;&lt;P class="p2"&gt;&lt;/P&gt;&lt;P class="p2"&gt;and for the consequent sets, like HR2 , it will do &lt;/P&gt;&lt;P class="p2" style="font-size: 13.3333330154419px;"&gt;data j;&lt;/P&gt;&lt;P class="p2" style="font-size: 13.3333330154419px;"&gt;set j HR2;&lt;/P&gt;&lt;P class="p2" style="font-size: 13.3333330154419px;"&gt;run;&lt;/P&gt;&lt;P class="p2" style="font-size: 13.3333330154419px;"&gt;&lt;/P&gt;&lt;P class="p2" style="font-size: 13.3333330154419px;"&gt;and so on&lt;/P&gt;&lt;P class="p2" style="font-size: 13.3333330154419px;"&gt;&lt;/P&gt;&lt;P class="p2" style="font-size: 13.3333330154419px;"&gt;So when I do a &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;%&lt;/SPAN&gt;&lt;STRONG style="font-size: 13.3333330154419px;"&gt;&lt;EM&gt;repeat_set&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;(n=&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;the code executes correctly&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;BUT, when I do anything larger than 1, ex &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;%&lt;/SPAN&gt;&lt;STRONG style="font-size: 13.3333330154419px;"&gt;&lt;EM&gt;repeat_set&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;(n=&lt;/SPAN&gt;&lt;SPAN class="s3" style="font-size: 13.3333330154419px;"&gt;&lt;STRONG&gt;5&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;The code combines only tables HR2-HR5. It seems as if HR1 contribution to the new set 'j' is "deleted" during the process.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;Any &lt;/SPAN&gt;suggestions&lt;SPAN style="font-size: 13.3333330154419px;"&gt;?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;Best regards&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 26 Jun 2015 01:15:28 GMT</pubDate>
    <dc:creator>ammarhm</dc:creator>
    <dc:date>2015-06-26T01:15:28Z</dc:date>
    <item>
      <title>Combining multiple datasets using a loop</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Combining-multiple-datasets-using-a-loop/m-p/214387#M11578</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;A quick question.&lt;/P&gt;&lt;P&gt;I have several datasets (HR1, HR2, HR3,.....HR 20)&lt;/P&gt;&lt;P&gt;I need to combine a number of these tables using (data..set) according to certain criteria, since this is a repetitive task I chose to build a macro like this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;/P&gt;&lt;P class="p2"&gt;&lt;SPAN class="s1"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/SPAN&gt; repeat_set(n=);&lt;/P&gt;&lt;P class="p2"&gt;&lt;SPAN class="s2"&gt;%do&lt;/SPAN&gt; var=&lt;SPAN class="s3"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN class="s2"&gt;%to&lt;/SPAN&gt; &amp;amp;n; &lt;/P&gt;&lt;P class="p2"&gt;Data j;&lt;/P&gt;&lt;P class="p2" style="font-size: 13.3333330154419px;"&gt;if &amp;amp;var=&lt;SPAN class="s3"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt; then do;&lt;/P&gt;&lt;P class="p2" style="font-size: 13.3333330154419px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set HR&amp;amp;var;&lt;/P&gt;&lt;P class="p2" style="font-size: 13.3333330154419px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P class="p2"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;else &lt;/SPAN&gt;if &amp;amp;var gt &lt;SPAN class="s3"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt; then do;&lt;/P&gt;&lt;P class="p2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set j HR&amp;amp;var;&lt;/P&gt;&lt;P class="p2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P class="p2"&gt;&lt;/P&gt;&lt;P class="p2"&gt;run;&lt;/P&gt;&lt;P class="p3"&gt;%end&lt;SPAN class="s4"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p4"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;SPAN class="s4"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;/P&gt;&lt;P class="p2"&gt;&lt;/P&gt;&lt;P class="p2"&gt;&lt;/P&gt;&lt;P class="p2"&gt;The reason why I am doing this is that the new dataset 'J' dose not exist from the beginning, so while looping, the idea is when the code takes the first HR set (HR1) it will create 'j' using the following:&lt;/P&gt;&lt;P class="p2"&gt;data j;&lt;/P&gt;&lt;P class="p2"&gt;set HR1;&lt;/P&gt;&lt;P class="p2"&gt;run;&lt;/P&gt;&lt;P class="p2"&gt;&lt;/P&gt;&lt;P class="p2"&gt;and for the consequent sets, like HR2 , it will do &lt;/P&gt;&lt;P class="p2" style="font-size: 13.3333330154419px;"&gt;data j;&lt;/P&gt;&lt;P class="p2" style="font-size: 13.3333330154419px;"&gt;set j HR2;&lt;/P&gt;&lt;P class="p2" style="font-size: 13.3333330154419px;"&gt;run;&lt;/P&gt;&lt;P class="p2" style="font-size: 13.3333330154419px;"&gt;&lt;/P&gt;&lt;P class="p2" style="font-size: 13.3333330154419px;"&gt;and so on&lt;/P&gt;&lt;P class="p2" style="font-size: 13.3333330154419px;"&gt;&lt;/P&gt;&lt;P class="p2" style="font-size: 13.3333330154419px;"&gt;So when I do a &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;%&lt;/SPAN&gt;&lt;STRONG style="font-size: 13.3333330154419px;"&gt;&lt;EM&gt;repeat_set&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;(n=&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;the code executes correctly&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;BUT, when I do anything larger than 1, ex &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;%&lt;/SPAN&gt;&lt;STRONG style="font-size: 13.3333330154419px;"&gt;&lt;EM&gt;repeat_set&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;(n=&lt;/SPAN&gt;&lt;SPAN class="s3" style="font-size: 13.3333330154419px;"&gt;&lt;STRONG&gt;5&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;The code combines only tables HR2-HR5. It seems as if HR1 contribution to the new set 'j' is "deleted" during the process.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;Any &lt;/SPAN&gt;suggestions&lt;SPAN style="font-size: 13.3333330154419px;"&gt;?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;Best regards&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Jun 2015 01:15:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Combining-multiple-datasets-using-a-loop/m-p/214387#M11578</guid>
      <dc:creator>ammarhm</dc:creator>
      <dc:date>2015-06-26T01:15:28Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple datasets using a loop</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Combining-multiple-datasets-using-a-loop/m-p/214388#M11579</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why not just combine them all in one step?&lt;/P&gt;&lt;P&gt;data want ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set hr1-hr20;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Jun 2015 01:18:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Combining-multiple-datasets-using-a-loop/m-p/214388#M11579</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-06-26T01:18:54Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple datasets using a loop</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Combining-multiple-datasets-using-a-loop/m-p/214389#M11580</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The reason is that it is a part of a larger code that I need to actively decide the number of tables to include, and I need to programatically be able to change one value in the code rather than changing it at several places&lt;/P&gt;&lt;P&gt;Anyhow, found the problem myself (missing %), but your code works too of course&lt;/P&gt;&lt;P&gt;Kind regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Jun 2015 01:27:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Combining-multiple-datasets-using-a-loop/m-p/214389#M11580</guid>
      <dc:creator>ammarhm</dc:creator>
      <dc:date>2015-06-26T01:27:42Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple datasets using a loop</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Combining-multiple-datasets-using-a-loop/m-p/214390#M11581</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How are you "actively" deciding how many tables to include?&amp;nbsp; Do you mean the parameter N to the macro?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let n=5 ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data J;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set hr1-hr&amp;amp;n;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Jun 2015 01:55:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Combining-multiple-datasets-using-a-loop/m-p/214390#M11581</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-06-26T01:55:07Z</dc:date>
    </item>
  </channel>
</rss>

