<?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 Identifying common column (variable) names from multiple tables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Identifying-common-column-variable-names-from-multiple-tables/m-p/746527#M234195</link>
    <description>&lt;P&gt;Suppose I have two tables.&lt;BR /&gt;&lt;BR /&gt;TableA contains the column names: &lt;STRONG&gt;Col1&lt;/STRONG&gt;, Col2,&amp;nbsp;&lt;STRONG&gt;Col3,&lt;/STRONG&gt; Col 4, Col 5&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;TableB contains the column names: &lt;STRONG&gt;Col1&lt;/STRONG&gt;, B2, &lt;STRONG&gt;Col3&lt;/STRONG&gt;, B4&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Now, I would like to create a function, taking &lt;U&gt;&lt;STRONG&gt;arbitrary&lt;/STRONG&gt;&lt;/U&gt; number of tables as input arguments and then returning the common columns of the tables used as input.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So for example:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;MyFun(TableA, TableB) = Col1, Col3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This would be a useful function when for instance looking for "keys" when working with joins in SQL. Does this kind of function exist or does anyone know how to code it?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thanks.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 08 Jun 2021 17:39:42 GMT</pubDate>
    <dc:creator>SasStatistics</dc:creator>
    <dc:date>2021-06-08T17:39:42Z</dc:date>
    <item>
      <title>Identifying common column (variable) names from multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-common-column-variable-names-from-multiple-tables/m-p/746527#M234195</link>
      <description>&lt;P&gt;Suppose I have two tables.&lt;BR /&gt;&lt;BR /&gt;TableA contains the column names: &lt;STRONG&gt;Col1&lt;/STRONG&gt;, Col2,&amp;nbsp;&lt;STRONG&gt;Col3,&lt;/STRONG&gt; Col 4, Col 5&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;TableB contains the column names: &lt;STRONG&gt;Col1&lt;/STRONG&gt;, B2, &lt;STRONG&gt;Col3&lt;/STRONG&gt;, B4&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Now, I would like to create a function, taking &lt;U&gt;&lt;STRONG&gt;arbitrary&lt;/STRONG&gt;&lt;/U&gt; number of tables as input arguments and then returning the common columns of the tables used as input.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So for example:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;MyFun(TableA, TableB) = Col1, Col3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This would be a useful function when for instance looking for "keys" when working with joins in SQL. Does this kind of function exist or does anyone know how to code it?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thanks.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jun 2021 17:39:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-common-column-variable-names-from-multiple-tables/m-p/746527#M234195</guid>
      <dc:creator>SasStatistics</dc:creator>
      <dc:date>2021-06-08T17:39:42Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying common column (variable) names from multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-common-column-variable-names-from-multiple-tables/m-p/746536#M234197</link>
      <description>&lt;P&gt;Here's a rough example. You could convert it to a macro to achieve your full functionality. &lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://gist.github.com/statgeek/95080ffddc5217af80248fd078dfbfeb" target="_blank" rel="noopener"&gt;https://gist.github.com/statgeek/95080ffddc5217af80248fd078dfbfeb&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;This may be useful as well, though likely overkill for what you're attempting.&lt;BR /&gt;&lt;A href="https://gist.github.com/statgeek/3b57ae085d9f7a36a2d95c15f04e72e6" target="_blank" rel="noopener"&gt;https://gist.github.com/statgeek/3b57ae085d9f7a36a2d95c15f04e72e6&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; /*Generate fake data to work with*/
	data class1;
		set sashelp.class;
		drop age sex;
	run;
	
	data class2;
		set sashelp.class;
		drop weight height;
	run;
	
	data class3;
		set sashelp.class;
		Order=1;
	run;
	
	data class4;
		set sashelp.class;
		keep name;
	run;
	
	data class5;
		set sashelp.class;
	run;
	
    /*Extract metadata from dictionary tables*/
	proc sql noprint;
		create table column_list as select memname, libname, name, type, 1 as count 
			from dictionary.columns where libname='WORK' and memname like 'CLASS%'
			/*ADD THE VARIABLE LIST HERE*/
			order by memname, name;
	quit;
	
    /*Transpose results to a more user friendly format*/
	proc transpose data=column_list out=flipped;
		by memname;
		id name;
		idlabel name;
		var count;
	run;
	
    /*Format output*/
	data want;
		retain memname;
		set flipped;
		array class(*) _NUMERIC_;
	
		do i=1 to dim(class);
	
			if class(i)=. then
				class(i)=0;
		end;
		All_Variables=sum(of _numeric_)-I;
		DROP I _NAME_;
	run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I'll leave it up to you to generalize it.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jun 2021 17:54:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-common-column-variable-names-from-multiple-tables/m-p/746536#M234197</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-06-08T17:54:14Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying common column (variable) names from multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-common-column-variable-names-from-multiple-tables/m-p/746541#M234198</link>
      <description>&lt;P&gt;I would take the same test data sets created by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;(Class1-Class5) and then run her PROC SQL, and then replace her PROC TRANSPOSE with this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=column_list;
    tables name/noprint out=Names;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;now you have a data set called NAMES where the number of times a variable appears is in the column named COUNT. From there, you can do whatever you need with this information. So if you want to know which names appear more than once (and how many times they appear) in these data sets, you just eliminate the variable names with COUNT=1.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jun 2021 18:25:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-common-column-variable-names-from-multiple-tables/m-p/746541#M234198</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-08T18:25:04Z</dc:date>
    </item>
  </channel>
</rss>

