<?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 Tables in Macro, Please help thanks. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Append-Tables-in-Macro-Please-help-thanks/m-p/319370#M70128</link>
    <description>&lt;P&gt;Hello, Ballardw,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Before I append all the tables together, I was trying to add one column to display the corresponding year and month, like “201301” for the data from the&amp;nbsp;month of MC201301, how would I modify the code to make it work?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried few ways, and it did not work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
    <pubDate>Thu, 15 Dec 2016 19:27:18 GMT</pubDate>
    <dc:creator>肉肉</dc:creator>
    <dc:date>2016-12-15T19:27:18Z</dc:date>
    <item>
      <title>Append Tables in Macro, Please help thanks.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-Tables-in-Macro-Please-help-thanks/m-p/318002#M69641</link>
      <description>&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;Hello guys, I was trying to append all the tables together which has the format of&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;MC201301.MALD_STMT, &lt;FONT color="#000080" face="Courier New"&gt;MC201302.MALD_STMT, MC201303.MALD_STMT......&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New"&gt;MC201611.MALD_STMT.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New"&gt;I can generate a list of 48 variables from the first set of code, and it gave me MC201301 to MC201612. but I could not Concatenatethese each value to pull the statement. Please help.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New"&gt;Thank you. &lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; yyyymmtest; &lt;/FONT&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;/*This is to create a variable as 'MCYYYYMM'*/&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;MC=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'MC'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; j = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;2013&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;to&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;2016&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; i = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;01&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;to&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;12&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;/*In here, "i" and "j" are numeric character*/&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;inew = put(i,&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;z2.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;); &lt;/FONT&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;/*convert "i" to be string character*/&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;Month1=j||strip(inew);&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Month = MC||strip(j)||strip(inew); &lt;/FONT&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;/*The output would be in the form of 'MC201301'*/&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; month &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;into&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;:NewMonth &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; yyyymmtest&lt;/FONT&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; test1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; i=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%to&lt;/FONT&gt; 48&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;amp;NewMonth(i)&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;..M&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;ALD_STMT;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2016 21:31:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-Tables-in-Macro-Please-help-thanks/m-p/318002#M69641</guid>
      <dc:creator>肉肉</dc:creator>
      <dc:date>2016-12-09T21:31:33Z</dc:date>
    </item>
    <item>
      <title>Re: Append Tables in Macro, Please help thanks.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-Tables-in-Macro-Please-help-thanks/m-p/318003#M69642</link>
      <description>&lt;P&gt;Please look at this code:&lt;/P&gt;
&lt;PRE&gt;data temp;
   /* maximum length of libname.dataset is 8+1+32= 41*/
   length dsname $ 41;
   do year=2013 to 2016;
      do month= 1 to 12;
         dsname = cats("MC",year,put(month,z2.),".MALD_STMT");
         output;
      end;
   end;
run;

proc sql noprint;
   select dsname into : Namelist separated by " "
   from temp;
quit;
/*%put &amp;amp;namelist;*/
data combined;
   set
      &amp;amp;namelist
   ;
run;&lt;/PRE&gt;
&lt;P&gt;Your code, while a good begining start has two actual errors. First the %do / %end block is not valid outside of a declared macro. How you used it is is what is referred to as "open code" and should have generated an error message.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second you would not want the ; immediately after the set name as the first one would end the SET statement.&lt;/P&gt;
&lt;P&gt;the generic code for that would look like:&lt;/P&gt;
&lt;P&gt;Set&lt;/P&gt;
&lt;P&gt;%do i= 1 %to &amp;amp;loopcounter;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; datasetname&amp;amp;i&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;; &amp;lt;= this ; end the "set" statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;again that would have to be in a defined macro.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2016 22:01:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-Tables-in-Macro-Please-help-thanks/m-p/318003#M69642</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-12-09T22:01:39Z</dc:date>
    </item>
    <item>
      <title>Re: Append Tables in Macro, Please help thanks.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-Tables-in-Macro-Please-help-thanks/m-p/318004#M69643</link>
      <description>&lt;P&gt;&lt;FONT size="3"&gt;Hello Ballardw, Thank you first of all! great help!&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;because the month Dec 2016 has not been finished, so I need to remove the last observation which is MC201612.MALD_STMT.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;I used the following data line to remove it, but it did not work. can you please tell me why?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;if&lt;SPAN&gt; last.dsname&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size="3"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;then delete&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;SPAN&gt;it did not work at all.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2016 22:28:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-Tables-in-Macro-Please-help-thanks/m-p/318004#M69643</guid>
      <dc:creator>肉肉</dc:creator>
      <dc:date>2016-12-09T22:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: Append Tables in Macro, Please help thanks.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-Tables-in-Macro-Please-help-thanks/m-p/318005#M69644</link>
      <description>&lt;P&gt;The FIRST. and LAST. are only valid when using BY group processing in the data step. And it is set for EACH level of the variable then with what we have done above it would delete everything.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Easiest&amp;nbsp;at this point might be to modify the PROC SQL:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
   select dsname into : Namelist separated by " "
   from temp
   where dsname ne "MC201612.MALD_STMT";
quit;

OR

proc sql noprint;
   select dsname into : Namelist separated by " "
   from temp
   where NOT (year=2016 and month=12);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Dec 2016 22:49:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-Tables-in-Macro-Please-help-thanks/m-p/318005#M69644</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-12-09T22:49:43Z</dc:date>
    </item>
    <item>
      <title>Re: Append Tables in Macro, Please help thanks.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-Tables-in-Macro-Please-help-thanks/m-p/318006#M69645</link>
      <description>&lt;P&gt;Thank you again! Its very educational.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2016 22:54:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-Tables-in-Macro-Please-help-thanks/m-p/318006#M69645</guid>
      <dc:creator>肉肉</dc:creator>
      <dc:date>2016-12-09T22:54:21Z</dc:date>
    </item>
    <item>
      <title>Re: Append Tables in Macro, Please help thanks.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-Tables-in-Macro-Please-help-thanks/m-p/319370#M70128</link>
      <description>&lt;P&gt;Hello, Ballardw,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Before I append all the tables together, I was trying to add one column to display the corresponding year and month, like “201301” for the data from the&amp;nbsp;month of MC201301, how would I modify the code to make it work?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried few ways, and it did not work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2016 19:27:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-Tables-in-Macro-Please-help-thanks/m-p/319370#M70128</guid>
      <dc:creator>肉肉</dc:creator>
      <dc:date>2016-12-15T19:27:18Z</dc:date>
    </item>
  </channel>
</rss>

