<?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: Create a merge table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-a-merge-table/m-p/388780#M93244</link>
    <description>&lt;P&gt;The vast majority of your requirements are satisfied by a simple program:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data a;&lt;/P&gt;
&lt;P&gt;set b1 b2 b3 b4 b5;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The only wrinkle is determining whether A already exists, in which case you would want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data a;&lt;/P&gt;
&lt;P&gt;set a b1 b2 b3 b4 b5;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are plenty of functions to determine whether a data set exists, and macro language could easily add or remove A from the SET statement.&lt;/P&gt;</description>
    <pubDate>Thu, 17 Aug 2017 13:22:48 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-08-17T13:22:48Z</dc:date>
    <item>
      <title>Create a merge table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-merge-table/m-p/388744#M93235</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I want to create a function which I am not sure it exists:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let say I have &lt;STRONG&gt;n tables&lt;/STRONG&gt;, named &lt;STRONG&gt;B1 to Bn &lt;/STRONG&gt;with a various number of variables, some of them can be common on several table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a &lt;STRONG&gt;table A&lt;/STRONG&gt; as a merge of all &amp;nbsp;Bi tables, creating a macro function:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;f(input_table, output_table)&lt;/PRE&gt;&lt;P&gt;which is doing the following thing:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- if &lt;STRONG&gt;output_table&lt;/STRONG&gt; doesn't exist, macro creates it as equal to &lt;STRONG&gt;input_table&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;- if &lt;STRONG&gt;output_table&lt;/STRONG&gt; already exists, macro&amp;nbsp;appends&amp;nbsp;the actual state of &lt;STRONG&gt;output_table&lt;/STRONG&gt; with &lt;STRONG&gt;input_table&lt;/STRONG&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;==&amp;gt; For each variabale of &lt;STRONG&gt;output_table&lt;/STRONG&gt;, existing in &lt;STRONG&gt;input_table&lt;/STRONG&gt;, macro appends like an easy proc appends&lt;/P&gt;&lt;P&gt;==&amp;gt; For each variable of &lt;STRONG&gt;output_table&lt;/STRONG&gt;, not existing in &lt;STRONG&gt;input_table&lt;/STRONG&gt;, macro leaves values empty&lt;/P&gt;&lt;P&gt;==&amp;gt; For each variable of &lt;STRONG&gt;input_table&lt;/STRONG&gt; not existing in &lt;STRONG&gt;output_table&lt;/STRONG&gt;, macro add this new variable to &lt;STRONG&gt;output_table&lt;/STRONG&gt;, and fill in values only from &lt;STRONG&gt;input_table&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then, I just need to call the function like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;do i = 1 to n;
f(Bi, A);
end;&lt;/PRE&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;STRONG&gt;&lt;U&gt;Exemple:&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let say I have four tables (variable names are in first row):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- B1:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;z y x
0 2 5
3 5 8
4 5 6
7 8 1&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-B2:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;y w v
4 5 6
2 9 9&lt;/PRE&gt;&lt;P&gt;-B3:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;u t s
0 0 0
1 1 1
2 2 2&lt;/PRE&gt;&lt;P&gt;-B4:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;z v r
1 5 6
4 4 4
9 8 7&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I call my function:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;f(B1,A);
f(B2,A);
f(B3,A);
f(B4,A);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;After the first call:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;A doesn't exist and is created as B1:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;z y x
0 2 5
3 5 8
4 5 6
7 8 1&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;After the second call:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;A is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;z y x w v
0 2 5 . .
3 5 8 . .
4 5 6 . .
7 8 1 . .
. 4 . 5 6
. 2 . 9 9&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;After the third call:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;A is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;z y x w v u t s
0 2 5 . . . . .
3 5 8 . . . . .
4 5 6 . . . . .
7 8 1 . . . . .
. 4 . 5 6 . . .
. 2 . 9 9 . . .
. . . . . 0 0 0
. . . . . 1 1 1
. . . . . 2 2 2&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;After the fouth and last call:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;A is:&lt;/P&gt;&lt;PRE&gt;z y x w v u t s r
0 2 5 . . . . . .
3 5 8 . . . . . .
4 5 6 . . . . . .
7 8 1 . . . . . .
. 4 . 5 6 . . . .
. 2 . 9 9 . . . .
. . . . . 0 0 0 .
. . . . . 1 1 1 .
. . . . . 2 2 2 .
1 . . . 5 . . . 6
4 . . . 4 . . . 4
9 . . . 8 . . . 7&lt;/PRE&gt;&lt;P&gt;I can't find how to write the macro, especially to detect if output_table exists or not. Can you help me doing it?&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2017 11:21:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-merge-table/m-p/388744#M93235</guid>
      <dc:creator>fabdu92</dc:creator>
      <dc:date>2017-08-17T11:21:21Z</dc:date>
    </item>
    <item>
      <title>Re: Create a merge table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-merge-table/m-p/388780#M93244</link>
      <description>&lt;P&gt;The vast majority of your requirements are satisfied by a simple program:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data a;&lt;/P&gt;
&lt;P&gt;set b1 b2 b3 b4 b5;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The only wrinkle is determining whether A already exists, in which case you would want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data a;&lt;/P&gt;
&lt;P&gt;set a b1 b2 b3 b4 b5;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are plenty of functions to determine whether a data set exists, and macro language could easily add or remove A from the SET statement.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2017 13:22:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-merge-table/m-p/388780#M93244</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-08-17T13:22:48Z</dc:date>
    </item>
    <item>
      <title>Re: Create a merge table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-merge-table/m-p/388785#M93246</link>
      <description>&lt;P&gt;Why to complicate a simple work ? Just do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data want;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp;set B1 B2 B3 ... Bn;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or even less coding:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data want; &lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; set B: ; &lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2017 13:32:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-merge-table/m-p/388785#M93246</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-08-17T13:32:35Z</dc:date>
    </item>
    <item>
      <title>Re: Create a merge table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-merge-table/m-p/388806#M93247</link>
      <description>&lt;P&gt;Thanks for the answer&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Before asking I tried to write the function like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro f(
	input_table,
	output_table);

%if %sysfunc(exists(&amp;amp;output_table.)) %then %do;
	data &amp;amp;output_table.; set &amp;amp;output_table. &amp;amp;input_table.;run;
%end;
%else %do;
	data &amp;amp;output_table.; set &amp;amp;input_table.; run;
%end;


%mend f;&lt;/PRE&gt;&lt;P&gt;But when I call it, I have an error:&lt;/P&gt;&lt;PRE&gt;ERROR: The EXISTS function referenced in the %SYSFUNC or %QSYSFUNC macro function is not found.&lt;/PRE&gt;&lt;P&gt;When I delete sysfunc and replace by&lt;/P&gt;&lt;PRE&gt;%exists(&amp;amp;output_table.)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I have an error:&lt;/P&gt;&lt;PRE&gt;ERROR: Required operator not found in expression: %exists(&amp;amp;output_table.) &lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Aug 2017 14:09:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-merge-table/m-p/388806#M93247</guid>
      <dc:creator>fabdu92</dc:creator>
      <dc:date>2017-08-17T14:09:41Z</dc:date>
    </item>
    <item>
      <title>Re: Create a merge table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-merge-table/m-p/388817#M93248</link>
      <description>&lt;P&gt;The function is EXIST (not existS) - try change &amp;nbsp;line to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;%sysfunc(&lt;STRONG&gt;exist&lt;/STRONG&gt;(&amp;amp;outtabel))&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2017 14:31:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-merge-table/m-p/388817#M93248</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-08-17T14:31:07Z</dc:date>
    </item>
  </channel>
</rss>

