<?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 Comparing and listing varaibles from two seperate datsets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Comparing-and-listing-varaibles-from-two-seperate-datsets/m-p/417475#M102546</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have similar datasets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dataset A has&amp;nbsp;376 variables and&lt;/P&gt;&lt;P&gt;Dataset B has 428 variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I get a list of the variables which are not in both datasets?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Thu, 30 Nov 2017 17:05:08 GMT</pubDate>
    <dc:creator>Adnan_Razaq</dc:creator>
    <dc:date>2017-11-30T17:05:08Z</dc:date>
    <item>
      <title>Comparing and listing varaibles from two seperate datsets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-and-listing-varaibles-from-two-seperate-datsets/m-p/417475#M102546</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have similar datasets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dataset A has&amp;nbsp;376 variables and&lt;/P&gt;&lt;P&gt;Dataset B has 428 variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I get a list of the variables which are not in both datasets?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2017 17:05:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-and-listing-varaibles-from-two-seperate-datsets/m-p/417475#M102546</guid>
      <dc:creator>Adnan_Razaq</dc:creator>
      <dc:date>2017-11-30T17:05:08Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing and listing varaibles from two seperate datsets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-and-listing-varaibles-from-two-seperate-datsets/m-p/417482#M102547</link>
      <description>&lt;P&gt;1. Get a list of variables from each data set&lt;/P&gt;
&lt;P&gt;Use either SASHELP.VCOLUMN or PROC CONTENTS&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2A. Use SQL to compare them&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2B. Use PROC COMPARE to compare the lists&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2C. Use a data step to do the comparison.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have an example of the 2C approach here - note this is a fully worked example so the first few steps are generating sample data. Please make sure to read the comments.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Here's a bit of a long way to generate the list of datasets with variables present.
This program looks at ALL variables, to restrict it to a select list, see the line of 
code to be modified via the comments.;


    /*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;&lt;A href="https://gist.github.com/statgeek/3b57ae085d9f7a36a2d95c15f04e72e6" target="_blank"&gt;https://gist.github.com/statgeek/3b57ae085d9f7a36a2d95c15f04e72e6&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2017 17:30:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-and-listing-varaibles-from-two-seperate-datsets/m-p/417482#M102547</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-30T17:30:11Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing and listing varaibles from two seperate datsets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-and-listing-varaibles-from-two-seperate-datsets/m-p/417483#M102548</link>
      <description>&lt;P&gt;And a slightly different implementation:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://gist.github.com/statgeek/e0b98c4627aa31a567e5" target="_blank"&gt;https://gist.github.com/statgeek/e0b98c4627aa31a567e5&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2017 17:29:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-and-listing-varaibles-from-two-seperate-datsets/m-p/417483#M102548</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-30T17:29:41Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing and listing varaibles from two seperate datsets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-and-listing-varaibles-from-two-seperate-datsets/m-p/417484#M102549</link>
      <description>&lt;P&gt;Proc Compare is one tool that provides that information (as well as if the same-named variables are of different types).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc compare base=datasetA compare=datasetb novalues listvar;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2017 17:31:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-and-listing-varaibles-from-two-seperate-datsets/m-p/417484#M102549</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-11-30T17:31:19Z</dc:date>
    </item>
  </channel>
</rss>

