<?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 Concatenate datasets within a single macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-datasets-within-a-single-macro/m-p/340244#M272665</link>
    <description>&lt;P&gt;%macro try(dsn=);&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table required as&lt;BR /&gt;select *&lt;BR /&gt;from &amp;amp;dsn.&lt;BR /&gt;where condition=x&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;%mend try;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm able to get the correct result if I&amp;nbsp;call&amp;nbsp;&amp;nbsp; %try(dsn=abc)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What if I have few dsn's and concatenate them by using set statement, within the same above macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thak yoiu.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 12 Mar 2017 17:28:25 GMT</pubDate>
    <dc:creator>West26</dc:creator>
    <dc:date>2017-03-12T17:28:25Z</dc:date>
    <item>
      <title>Concatenate datasets within a single macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-datasets-within-a-single-macro/m-p/340244#M272665</link>
      <description>&lt;P&gt;%macro try(dsn=);&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table required as&lt;BR /&gt;select *&lt;BR /&gt;from &amp;amp;dsn.&lt;BR /&gt;where condition=x&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;%mend try;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm able to get the correct result if I&amp;nbsp;call&amp;nbsp;&amp;nbsp; %try(dsn=abc)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What if I have few dsn's and concatenate them by using set statement, within the same above macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thak yoiu.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Mar 2017 17:28:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-datasets-within-a-single-macro/m-p/340244#M272665</guid>
      <dc:creator>West26</dc:creator>
      <dc:date>2017-03-12T17:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate datasets within a single macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-datasets-within-a-single-macro/m-p/340245#M272666</link>
      <description>&lt;P&gt;You could do something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data abc;
  type='abc';
  condition=1;
  output;
run;

data def;
  type='def';
  condition=1;
  output;
run;

%macro try(dsn=);
  proc sql;
    create table required as
      select *
        from &amp;amp;dsn.
        %if %sysfunc(countw(&amp;amp;tdsn.)) gt 1 %then %do i=2 %to %sysfunc(countw(&amp;amp;tdsn.));
          union 
            select *
              from %scan(&amp;amp;tdsn.,&amp;amp;i.)
        %end;
  where condition=1
    ;
  quit;
%mend try;

%try(dsn=abc def)
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Mar 2017 17:49:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-datasets-within-a-single-macro/m-p/340245#M272666</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-12T17:49:38Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate datasets within a single macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-datasets-within-a-single-macro/m-p/340253#M272667</link>
      <description>&lt;P&gt;It is much easier if you just use a data step instead of trying to use PROC SQL. &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro try(dsn=);
data required;
  set &amp;amp;dsn ;
  where condition=x ;
run;
%mend try;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can then just call it with a space delimited list of dataset names.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%try(dsn=A B C)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 12 Mar 2017 19:10:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-datasets-within-a-single-macro/m-p/340253#M272667</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-03-12T19:10:30Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate datasets within a single macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-datasets-within-a-single-macro/m-p/340345#M272668</link>
      <description>&lt;P&gt;Which of course raises the question of why the macro at all as:&lt;/P&gt;
&lt;PRE&gt;%let dsn=abc def;

data required;
  set &amp;amp;dsn.;
  where conditon=x;
run;&lt;/PRE&gt;
&lt;P&gt;Or even:&lt;/P&gt;
&lt;PRE&gt;data required;
  set abc def;
  where conditon=x;
run;&lt;/PRE&gt;
&lt;P&gt;So the given example is pointless obfucating the code.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2017 09:35:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-datasets-within-a-single-macro/m-p/340345#M272668</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-03-13T09:35:36Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate datasets within a single macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-datasets-within-a-single-macro/m-p/340462#M272669</link>
      <description>&lt;P&gt;And if all your datasets that you want to process&amp;nbsp;in a library start with the same characters :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data required;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set mylib.abc: ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; where condition=x;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;would combine: mylib.abc1 mylib.abc2 mylib.abcpdq;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;any of the sets that start with abc.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2017 15:40:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-datasets-within-a-single-macro/m-p/340462#M272669</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-13T15:40:04Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate datasets within a single macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-datasets-within-a-single-macro/m-p/341808#M272670</link>
      <description>Sorry that I couldn't back this long. Thank you all for the your time.</description>
      <pubDate>Thu, 16 Mar 2017 22:54:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-datasets-within-a-single-macro/m-p/341808#M272670</guid>
      <dc:creator>West26</dc:creator>
      <dc:date>2017-03-16T22:54:26Z</dc:date>
    </item>
  </channel>
</rss>

