<?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: PROC COMPARE output list of variables not in base dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-COMPARE-output-list-of-variables-not-in-base-dataset/m-p/481630#M124616</link>
    <description>&lt;P&gt;Possibly, but I usually roll my own.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*create example data;
data class;
set sashelp.class;
run;

data class2;
set sashelp.class;
drop age sex;
run;

*set macro variables;
%let lib_master=work;
%let master=Class2;
%let lib_sub=work;
%let sub=Class;
%let dlm=" ";


*create a variable list of missing variables;
proc sql noprint;
select name into :drop_list separated &amp;amp;dlm.
from sashelp.vcolumn
where upper(libname)=upper("&amp;amp;lib_sub.") 
and upper(memname) = upper("&amp;amp;sub")
and name not in (select name 
                from sashelp.vcolumn 
                where upper(libname)=upper("&amp;amp;lib_master.") 
                and upper(memname) = upper("&amp;amp;master"));
quit;

*show results;
%put &amp;amp;drop_list;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And I have an example here of a more complex approach that does what I call a variable report.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&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, 26 Jul 2018 18:11:38 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-07-26T18:11:38Z</dc:date>
    <item>
      <title>PROC COMPARE output list of variables not in base dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-COMPARE-output-list-of-variables-not-in-base-dataset/m-p/481612#M124611</link>
      <description>&lt;P&gt;Using PROC COMPARE, is there a way to output the list of variables found in Dataset A but not in Dataset B? I want to extract the list of variables so I can drop them from the comparison dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jul 2018 17:27:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-COMPARE-output-list-of-variables-not-in-base-dataset/m-p/481612#M124611</guid>
      <dc:creator>nd</dc:creator>
      <dc:date>2018-07-26T17:27:50Z</dc:date>
    </item>
    <item>
      <title>Re: PROC COMPARE output list of variables not in base dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-COMPARE-output-list-of-variables-not-in-base-dataset/m-p/481630#M124616</link>
      <description>&lt;P&gt;Possibly, but I usually roll my own.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*create example data;
data class;
set sashelp.class;
run;

data class2;
set sashelp.class;
drop age sex;
run;

*set macro variables;
%let lib_master=work;
%let master=Class2;
%let lib_sub=work;
%let sub=Class;
%let dlm=" ";


*create a variable list of missing variables;
proc sql noprint;
select name into :drop_list separated &amp;amp;dlm.
from sashelp.vcolumn
where upper(libname)=upper("&amp;amp;lib_sub.") 
and upper(memname) = upper("&amp;amp;sub")
and name not in (select name 
                from sashelp.vcolumn 
                where upper(libname)=upper("&amp;amp;lib_master.") 
                and upper(memname) = upper("&amp;amp;master"));
quit;

*show results;
%put &amp;amp;drop_list;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And I have an example here of a more complex approach that does what I call a variable report.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&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, 26 Jul 2018 18:11:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-COMPARE-output-list-of-variables-not-in-base-dataset/m-p/481630#M124616</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-26T18:11:38Z</dc:date>
    </item>
    <item>
      <title>Re: PROC COMPARE output list of variables not in base dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-COMPARE-output-list-of-variables-not-in-base-dataset/m-p/481637#M124617</link>
      <description>&lt;P&gt;Any of the information that is part of a printed report would also be available through ODS.&amp;nbsp; But you will have to figure out how to capture the right data set via ODS (and what the structure of that data set looks like.)&amp;nbsp; To begin, add this before running PROC COMPARE:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ods trace on;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then run the program that includes both this statement and the PROC COMPARE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This will tell you the names of the various pieces of output as far as ODS is concerned.&amp;nbsp; Hopefully, one of the names looks like the right one (although its possible you would need to explore more than one to find the right one).&amp;nbsp; At any rate, take a look at how you capture a piece of ODS output:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ods output ods_name_for_output_file = your_name_for_sas_dataset_to_hold_results;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you can run a PROC PRINT and PROC CONTENTS on the file you have captured to get a feel for what is in it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Even if this sounds like work, I recommend doing it.&amp;nbsp; It is something that will come in handy in the future.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jul 2018 18:34:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-COMPARE-output-list-of-variables-not-in-base-dataset/m-p/481637#M124617</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-07-26T18:34:02Z</dc:date>
    </item>
    <item>
      <title>Re: PROC COMPARE output list of variables not in base dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-COMPARE-output-list-of-variables-not-in-base-dataset/m-p/481639#M124618</link>
      <description>&lt;P&gt;In general I agree, however the ODS tables out of PROC COMPARE are pretty bad IME. If they've changed in the last two years that would be good though.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="delete_proc_compare.JPG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/22051i5E64331DECB0B31D/image-size/large?v=v2&amp;amp;px=999" role="button" title="delete_proc_compare.JPG" alt="delete_proc_compare.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods output compareVariables=Find;
proc compare data=class compare=class2 all;
run;&lt;/CODE&gt;&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;</description>
      <pubDate>Thu, 26 Jul 2018 18:39:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-COMPARE-output-list-of-variables-not-in-base-dataset/m-p/481639#M124618</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-26T18:39:16Z</dc:date>
    </item>
    <item>
      <title>Re: PROC COMPARE output list of variables not in base dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-COMPARE-output-list-of-variables-not-in-base-dataset/m-p/481654#M124627</link>
      <description>&lt;P&gt;Thanks! Here's my modified code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;ods&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; compareVariables=Find(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;where&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;type&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"d"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;compare&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;base&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=a &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;compare&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=b &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;listvar&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;ods&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;output&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;close&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; find;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; find;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;vars=scan(batch,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; missing(vars) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;delete&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;print&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;data&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=find;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;var&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; vars;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jul 2018 19:26:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-COMPARE-output-list-of-variables-not-in-base-dataset/m-p/481654#M124627</guid>
      <dc:creator>nd</dc:creator>
      <dc:date>2018-07-26T19:26:13Z</dc:date>
    </item>
    <item>
      <title>Re: PROC COMPARE output list of variables not in base dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-COMPARE-output-list-of-variables-not-in-base-dataset/m-p/602506#M174460</link>
      <description>&lt;P&gt;Actually it could be more useful to use output datasets from Proc Contents.&amp;nbsp; You can merge on variable names from as many input files as you want and use (in=x) flags to check on variables in common in multiple files (or those missing from a particular file, etc.)&lt;/P&gt;
&lt;P&gt;eg,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;option validvarname=upcase;&amp;nbsp; **because you want to merge on variable name and want upper/lower/mixed case variants to be the same;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;proc contents data=deanna.deanna_merge_19_06_28 noprint out= deanna&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;(keep= label libname memname name &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;) nodetails;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;data deanna;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;set deanna;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;rename memname = deanna_ds&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;libname = deanna_lib;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;label memname = "deanna_merge_19_06_28";&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;.....&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;.....&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;*repeat for each dataset of interest;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data POR.POR_de_gin_usnd;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;informat name POR_unused POR_used usnd1_unused usd2_unused D_or_G &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;label ;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;merge &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;usound1 (in=u1)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;usound2 (in=u2)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;ginna (in=g)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;deanna (in=d)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;POR2 (in=p)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;by name;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;D_or_G = (g = 1 | d = 1);&amp;nbsp; *** existing analysis files;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;usnd1_unused = (u1 = 1 &amp;amp; (d = 0 &amp;amp; g = 0));&amp;nbsp; **Ultrasound 1st trimester vars not used;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;usd2_unused = (u2 = 1 &amp;amp; (d = 0 &amp;amp; g = 0));&amp;nbsp;&amp;nbsp; **Ultrasound 2nd trimester vars not used;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;POR_unused = (p = 1 &amp;amp; D_or_G = 0); *** Preg outcome variables not yet used;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;POR_used = (p = 1 &amp;amp; D_or_G = 1)&amp;nbsp; &amp;nbsp; &amp;nbsp;*** Preg outcome variables already used;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2019 17:27:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-COMPARE-output-list-of-variables-not-in-base-dataset/m-p/602506#M174460</guid>
      <dc:creator>BobMcC___</dc:creator>
      <dc:date>2019-11-07T17:27:12Z</dc:date>
    </item>
  </channel>
</rss>

