<?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 Remove non-common variables from concatenation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Remove-non-common-variables-from-concatenation/m-p/780505#M248710</link>
    <description>&lt;P&gt;I want to concatenate two datasets (HAVE1 &amp;amp; HAVE2) and obtain a new dataset that only contains the variables that are in common (WANT) without having to explicitly DROP variables from the concatenated dataset. When I combine the two datasets using the SET statement (CONCAT), I get all variables from both of the original datasets (GET).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EXAMPLE CODE:&lt;/P&gt;&lt;P&gt;data have1;&lt;BR /&gt;input var1 var2;&lt;BR /&gt;datalines;&lt;BR /&gt;11 21&lt;BR /&gt;12 22&lt;BR /&gt;13 23&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have2;&lt;BR /&gt;input var1 var2 var3;&lt;BR /&gt;datalines;&lt;BR /&gt;14 24 31&lt;BR /&gt;15 25 32&lt;BR /&gt;16 26 33&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;input var1 var2;&lt;BR /&gt;datalines;&lt;BR /&gt;11 21&lt;BR /&gt;12 22&lt;BR /&gt;13 23&lt;BR /&gt;14 24&lt;BR /&gt;15 25&lt;BR /&gt;16 26&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data concat;&lt;BR /&gt;set have1 have2;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data get;&lt;BR /&gt;input var1 var2 var3;&lt;BR /&gt;datalines;&lt;BR /&gt;11 21 .&lt;BR /&gt;12 22 .&lt;BR /&gt;13 23 .&lt;BR /&gt;14 24 31&lt;BR /&gt;15 25 32&lt;BR /&gt;16 26 33&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Tue, 16 Nov 2021 17:42:49 GMT</pubDate>
    <dc:creator>edwolfe</dc:creator>
    <dc:date>2021-11-16T17:42:49Z</dc:date>
    <item>
      <title>Remove non-common variables from concatenation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-non-common-variables-from-concatenation/m-p/780505#M248710</link>
      <description>&lt;P&gt;I want to concatenate two datasets (HAVE1 &amp;amp; HAVE2) and obtain a new dataset that only contains the variables that are in common (WANT) without having to explicitly DROP variables from the concatenated dataset. When I combine the two datasets using the SET statement (CONCAT), I get all variables from both of the original datasets (GET).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EXAMPLE CODE:&lt;/P&gt;&lt;P&gt;data have1;&lt;BR /&gt;input var1 var2;&lt;BR /&gt;datalines;&lt;BR /&gt;11 21&lt;BR /&gt;12 22&lt;BR /&gt;13 23&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have2;&lt;BR /&gt;input var1 var2 var3;&lt;BR /&gt;datalines;&lt;BR /&gt;14 24 31&lt;BR /&gt;15 25 32&lt;BR /&gt;16 26 33&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;input var1 var2;&lt;BR /&gt;datalines;&lt;BR /&gt;11 21&lt;BR /&gt;12 22&lt;BR /&gt;13 23&lt;BR /&gt;14 24&lt;BR /&gt;15 25&lt;BR /&gt;16 26&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data concat;&lt;BR /&gt;set have1 have2;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data get;&lt;BR /&gt;input var1 var2 var3;&lt;BR /&gt;datalines;&lt;BR /&gt;11 21 .&lt;BR /&gt;12 22 .&lt;BR /&gt;13 23 .&lt;BR /&gt;14 24 31&lt;BR /&gt;15 25 32&lt;BR /&gt;16 26 33&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Nov 2021 17:42:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-non-common-variables-from-concatenation/m-p/780505#M248710</guid>
      <dc:creator>edwolfe</dc:creator>
      <dc:date>2021-11-16T17:42:49Z</dc:date>
    </item>
    <item>
      <title>Re: Remove non-common variables from concatenation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-non-common-variables-from-concatenation/m-p/780515#M248718</link>
      <description>&lt;P&gt;This does it, but it depends on exactly what you want. If you want duplicates removed, you can omit the `ALL` from the `UNION` operator. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table 	want2 as
		select
					*
		from
					have1
						union corr all 
		select
					*
		from
					have2;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;var1 var2 
11 21 
12 22 
13 23 
14 24 
15 25 
16 26 
&lt;/PRE&gt;
&lt;P&gt;I think that's the difference between the two, but someone can correct me if I'm mistaken.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Nov 2021 18:04:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-non-common-variables-from-concatenation/m-p/780515#M248718</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2021-11-16T18:04:58Z</dc:date>
    </item>
    <item>
      <title>Re: Remove non-common variables from concatenation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-non-common-variables-from-concatenation/m-p/780527#M248723</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select t1.name into :keeplist separated by" "
from dictionary.columns t1 inner join dictionary.columns t2
on upcase(t1.name) = upcase(t2.name)
where t1.libname = "LIB1" and t1.memname = "DS1"
and t2.libname = "LIB2" and t2.memname = "DS2";
quit;

data want;
set
  lib1.ds1
  lib2.ds2
;
keep &amp;amp;keeplist.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Nov 2021 18:55:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-non-common-variables-from-concatenation/m-p/780527#M248723</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-11-16T18:55:57Z</dc:date>
    </item>
  </channel>
</rss>

