<?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: merge data sets when some of them are not existing in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/merge-data-sets-when-some-of-them-are-not-existing/m-p/715876#M221155</link>
    <description>&lt;P&gt;You need to use %QSYSFUNC to execute the EXIST function for this. For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
input id x;
cards;
1 10
2 20
;
run;

data b;
input id w;
cards;
1 12
2 23
;
run;


data d;
input id y;
cards;
1 30
2 50
;
run;

 
data wanted;
merge
%if %qsysfunc(exist(a)) %then %do; a %end;
%if %qsysfunc(exist(b)) %then %do; b %end;
%if %qsysfunc(exist(c)) %then %do; c %end;
%if %qsysfunc(exist(d)) %then %do; d %end;
;
by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 01 Feb 2021 19:22:09 GMT</pubDate>
    <dc:creator>SASJedi</dc:creator>
    <dc:date>2021-02-01T19:22:09Z</dc:date>
    <item>
      <title>merge data sets when some of them are not existing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-data-sets-when-some-of-them-are-not-existing/m-p/715770#M221117</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to merge data sets and sometimes some of them are not exisiting.&lt;/P&gt;
&lt;P&gt;What is the way that there will not be an error&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
input id x;
cards;
1 10
2 20
;
run;

data b;
input id w;
cards;
1 12
2 23
;
run;


data c;
input id y;
cards;
1 30
2 50
;
run;

 
data wanted;
merge
%if_exits(a)
%if_exits(b)
%if_exits(c)
%if_exits(d)
%if_exits(e)
;
by id;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Feb 2021 13:14:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-data-sets-when-some-of-them-are-not-existing/m-p/715770#M221117</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-02-01T13:14:20Z</dc:date>
    </item>
    <item>
      <title>Re: merge data sets when some of them are not existing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-data-sets-when-some-of-them-are-not-existing/m-p/715772#M221119</link>
      <description>&lt;P&gt;Are you asking how to create the %IF_EXIST() macro?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro if_exists(dataset);
%if %sysfunc(exist(&amp;amp;dataset)) %then &amp;amp;dataset ;
%mend if_exists;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But watch out if none of them exist.&amp;nbsp; If you a MERGE statement with no datasets specified. Like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data wanted;
  merge ;
  by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then rather than doing nothing it will use the dataset named in the &amp;amp;SYSLAST macro variable. In other words the last created dataset.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 13:24:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-data-sets-when-some-of-them-are-not-existing/m-p/715772#M221119</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-02-01T13:24:06Z</dc:date>
    </item>
    <item>
      <title>Re: merge data sets when some of them are not existing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-data-sets-when-some-of-them-are-not-existing/m-p/715876#M221155</link>
      <description>&lt;P&gt;You need to use %QSYSFUNC to execute the EXIST function for this. For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
input id x;
cards;
1 10
2 20
;
run;

data b;
input id w;
cards;
1 12
2 23
;
run;


data d;
input id y;
cards;
1 30
2 50
;
run;

 
data wanted;
merge
%if %qsysfunc(exist(a)) %then %do; a %end;
%if %qsysfunc(exist(b)) %then %do; b %end;
%if %qsysfunc(exist(c)) %then %do; c %end;
%if %qsysfunc(exist(d)) %then %do; d %end;
;
by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Feb 2021 19:22:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-data-sets-when-some-of-them-are-not-existing/m-p/715876#M221155</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2021-02-01T19:22:09Z</dc:date>
    </item>
    <item>
      <title>Re: merge data sets when some of them are not existing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-data-sets-when-some-of-them-are-not-existing/m-p/715910#M221169</link>
      <description>&lt;P&gt;If you have an older sas release:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT;
  merge %sysfunc(ifc(%sysfunc(exist(A)),A,))
        %sysfunc(ifc(%sysfunc(exist(B)),B,))
        %sysfunc(ifc(%sysfunc(exist(C)),C,));
  by ID;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;[Edited as I had left out one&amp;nbsp;&lt;CODE class=" language-sas"&gt;%sysfunc(&lt;/CODE&gt; call]&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2021 21:45:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-data-sets-when-some-of-them-are-not-existing/m-p/715910#M221169</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-02-02T21:45:13Z</dc:date>
    </item>
    <item>
      <title>Re: merge data sets when some of them are not existing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-data-sets-when-some-of-them-are-not-existing/m-p/716150#M221283</link>
      <description>So true, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt; - versions of SAS before SAS 9.4M5 did not allow conditional macro statements in open code.</description>
      <pubDate>Tue, 02 Feb 2021 17:32:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-data-sets-when-some-of-them-are-not-existing/m-p/716150#M221283</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2021-02-02T17:32:36Z</dc:date>
    </item>
    <item>
      <title>Re: merge data sets when some of them are not existing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-data-sets-when-some-of-them-are-not-existing/m-p/716160#M221287</link>
      <description>&lt;P&gt;It seems silly to use %QSYSFUNC() instead of %SYSFUNC() to call a function that only returns 0 or 1. There is no reason to add macro quoting to that result.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2021 17:57:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-data-sets-when-some-of-them-are-not-existing/m-p/716160#M221287</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-02-02T17:57:00Z</dc:date>
    </item>
    <item>
      <title>Re: merge data sets when some of them are not existing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-data-sets-when-some-of-them-are-not-existing/m-p/717570#M221929</link>
      <description>&lt;P&gt;You say silly, I say prudent. Potato, poTAHto.... In my 25 years of macro programming, I've expended many manhours troubleshooting my programs (an other people's programs) only to find that the root problem was a failure to quote text resolved from a macro process. There is no reason that a macro process should produce unquoted text unless the text being produced is executable macro code. So over the years, I've developed the habit of quoting all text produced by my macro processes unless I to execute it. And it's proved to be an excellent habit. It has significanlty reduced programming bugs, with a very satisfactory correlated reduction in debugging time. I dont intend to be precriptive here - feel free to use SYSFUNC if you prefer. But since I didn't intend to execut the result produced by the SAS function, I chose QSYSFUNC, and I stand by my choice...&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2021 14:03:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-data-sets-when-some-of-them-are-not-existing/m-p/717570#M221929</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2021-02-08T14:03:08Z</dc:date>
    </item>
    <item>
      <title>Re: merge data sets when some of them are not existing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-data-sets-when-some-of-them-are-not-existing/m-p/717596#M221941</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13728"&gt;@SASJedi&lt;/a&gt;&amp;nbsp; Usually I find that debugging errors caused by not adding macro quoting is easier. They typically fail in spectacular ways. It is strange behavior when macro quoting is added in the wrong places that are usually more difficult to figure out as the generated SAS code looks valid, but the macro quoting causes it be interpreted incorrectly.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2021 15:37:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-data-sets-when-some-of-them-are-not-existing/m-p/717596#M221941</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-02-08T15:37:31Z</dc:date>
    </item>
  </channel>
</rss>

