<?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: SAS Macro: Merge only existing datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Merge-only-existing-datasets/m-p/259295#M50146</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let monlist = 06 12;

data Merged;
  set
  %do YEAR=&amp;amp;FIRSTYR %TO &amp;amp;LASTYR;
	%do i = 1 %to %sysfunc(countw(&amp;amp;monlist.));
    	%let monthf = %sysfunc(putn(%scan(&amp;amp;monlist.,&amp;amp;i.),z2.));
        %if %sysfunc(exist(&lt;FONT face="courier new,courier"&gt;Merged&amp;amp;YEAR.&amp;amp;MONTHF&lt;/FONT&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;)) %then %do;
           Merged&amp;amp;YEAR.&amp;amp;MONTHF
          %end;
  	%end; 
  %end;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Corrected thanks to &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh﻿&lt;/a&gt;.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 29 Mar 2016 01:31:23 GMT</pubDate>
    <dc:creator>SASKiwi</dc:creator>
    <dc:date>2016-03-29T01:31:23Z</dc:date>
    <item>
      <title>SAS Macro: Merge only existing datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Merge-only-existing-datasets/m-p/259294#M50145</link>
      <description>&lt;P&gt;Using SAS EG 7.1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically for &amp;amp;LASTYEAR, the dataset with MONTHF =12 may not exist. So is there a way to ensure only the existing datasets are merged? Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%let monlist = 06 12;

data Merged;
  set
  %do YEAR=&amp;amp;FIRSTYR %TO &amp;amp;LASTYR;
	%do i = 1 %to %sysfunc(countw(&amp;amp;monlist.));
    	%let monthf = %sysfunc(putn(%scan(&amp;amp;monlist.,&amp;amp;i.),z2.));
         Merged&amp;amp;YEAR.&amp;amp;MONTHF
  	%end; 
  %end;

run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Mar 2016 01:25:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Merge-only-existing-datasets/m-p/259294#M50145</guid>
      <dc:creator>apple</dc:creator>
      <dc:date>2016-03-28T01:25:56Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro: Merge only existing datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Merge-only-existing-datasets/m-p/259295#M50146</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let monlist = 06 12;

data Merged;
  set
  %do YEAR=&amp;amp;FIRSTYR %TO &amp;amp;LASTYR;
	%do i = 1 %to %sysfunc(countw(&amp;amp;monlist.));
    	%let monthf = %sysfunc(putn(%scan(&amp;amp;monlist.,&amp;amp;i.),z2.));
        %if %sysfunc(exist(&lt;FONT face="courier new,courier"&gt;Merged&amp;amp;YEAR.&amp;amp;MONTHF&lt;/FONT&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;)) %then %do;
           Merged&amp;amp;YEAR.&amp;amp;MONTHF
          %end;
  	%end; 
  %end;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Corrected thanks to &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh﻿&lt;/a&gt;.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2016 01:31:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Merge-only-existing-datasets/m-p/259295#M50146</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2016-03-29T01:31:23Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro: Merge only existing datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Merge-only-existing-datasets/m-p/259306#M50155</link>
      <description>&lt;P&gt;You're appending (stacking datasets) not merging.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have the option, consider using a variable list or shortcut list instead of a macro to list the datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example you can can use the following to append all datasets that start with MONTH.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Set MONTH:;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you can use the following to append a series with each year and then anything that starts with Month2007, Month2008 and Month2009 will be included.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Set Month2007: Month2008: Month2009:;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Mar 2016 03:39:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Merge-only-existing-datasets/m-p/259306#M50155</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-03-28T03:39:50Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro: Merge only existing datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Merge-only-existing-datasets/m-p/259401#M50193</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/2829"&gt;@apple﻿&lt;/a&gt;: The SET statement needs a closing semicolon after the second %END statement.&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi﻿&lt;/a&gt;:&amp;nbsp;The argument of EXIST should be &lt;FONT face="courier new,courier"&gt;Merged&amp;amp;YEAR.&amp;amp;MONTHF&lt;/FONT&gt;. Interestingly, if none of the datasets existed, the resulting "empty" &lt;FONT face="courier new,courier"&gt;SET;&lt;/FONT&gt; statement would be interpreted as &lt;FONT face="courier new,courier"&gt;SET _LAST_;&lt;/FONT&gt; and thus possibly read some random dataset.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Mar 2016 17:52:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Merge-only-existing-datasets/m-p/259401#M50193</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-03-28T17:52:23Z</dc:date>
    </item>
  </channel>
</rss>

