<?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 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/499903#M133060</link>
    <description>&lt;P&gt;Just for fun.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards expandtabs truncover;
input (Anumber	Bnumber	V1	V2	V3	V4	V5	V6	V7	V8	V87) ($);
cards;
1	A12	E	E	E	E	E	E	E	E	-1
2	A21	E	E	E	E	E	E	E	E	-5
3	B12	E	E	E	E	E	E	E	E	-1
4	B21	E	E	E	E	E	E	E	E	1
5	B23	E	E	E	E	E	E	E	E	-1
6	C24	E	E	E	E	E	E	E	E	-1
7	C26	E	E	E	E	E	E	E	E	1
8	C61	E	E	E	E	E	E	E	E	-1
9	D14	E	E	E	E	E	E	E	E	-1
10	D19	E	E	E	E	E	E	E	E	-5
11	D21	E	E	E	E	E	E	E	E	-5
12	D47	E	E	E	E	E	E	E	E	1
13	D81	E	E	E	E	E	E	E	E	1
14	D97	E	E	E	E	E	E	E	E	-1
15	D99	E	E	E	E	E	E	E	E	-1
;
run;
data _null_;
 set sashelp.vcolumn(where=(libname='WORK' and memname='HAVE')) end=last;
 if _n_=1 then call execute('proc sql;create table temp as select ');
 call execute(catx(' ','min(',name,')=max(',name,') as ',name));
 if last then call execute('from have;quit;');
  else call execute(',');
run;
proc transpose data=temp out=temp1;
run;
proc sql noprint;
 select _name_ into :keep separated by ' '
  from temp1
   where col1=0;
quit;
data want;
 set have;
 keep &amp;amp;keep;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 28 Sep 2018 13:47:59 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2018-09-28T13:47:59Z</dc:date>
    <item>
      <title>Proc Compare</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/499540#M132951</link>
      <description>&lt;P&gt;Hello community experts,&lt;/P&gt;&lt;P&gt;Please assist me in understanding how to drop columns from my final output dataset table if the column has all equal test results.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have many SAS datasets that I use&amp;nbsp;proc compare to find none equals and looking over them to find the columns of interest is tedious.&lt;/P&gt;&lt;P&gt;(1 of table containing 881 variables and 3.2 million records, So the examples below have been modified for simplicity).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc compare base=&amp;amp;mydata. compare=&amp;amp;mydata_new. out=&amp;amp;mydata._&amp;amp;mydata_new.(drop=_TYPE_ _obs_) outnoequal;
	by &amp;amp;var1. &amp;amp;var2. ;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;After running proc compare has completed I obtain information much like the below example. &amp;nbsp;&lt;/P&gt;&lt;P&gt;Want 1:&amp;nbsp; In this case example, I want the final dataset to only contain columns Anumber, Bnumber and V87 since V87 was the only column found to have differences.&amp;nbsp; I want to drop columns V1 - V8 because they are all equal.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Anumber	Bnumber	V1	V2	V3	V4	V5	V6	V7	V8	V87
1	A12	E	E	E	E	E	E	E	E	-1
2	A21	E	E	E	E	E	E	E	E	-5
3	B12	E	E	E	E	E	E	E	E	-1
4	B21	E	E	E	E	E	E	E	E	1
5	B23	E	E	E	E	E	E	E	E	-1
6	C24	E	E	E	E	E	E	E	E	-1
7	C26	E	E	E	E	E	E	E	E	1
8	C61	E	E	E	E	E	E	E	E	-1
9	D14	E	E	E	E	E	E	E	E	-1
10	D19	E	E	E	E	E	E	E	E	-5
11	D21	E	E	E	E	E	E	E	E	-5
12	D47	E	E	E	E	E	E	E	E	1
13	D81	E	E	E	E	E	E	E	E	1
14	D97	E	E	E	E	E	E	E	E	-1
15	D99	E	E	E	E	E	E	E	E	-1&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Want 2:&amp;nbsp; While &lt;SPAN&gt;in this 2nd case I w&lt;/SPAN&gt;&lt;SPAN&gt;ant&lt;/SPAN&gt;&lt;SPAN&gt; the final dataset to only contain columns Anumber, Bnumber, V3, V6 and V87 since these columns were found to have differences.&amp;nbsp; I want to drop &lt;/SPAN&gt;&lt;SPAN&gt;columns V1, V2, V4, V5, V7 and V8 because they are all equal.&lt;/SPAN&gt; .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Anumber	Bnumber	V1	V2	V3	V4	V5	V6	V7	V8	V87
1	A12	E	E	2	E	E	E	E	E	-1
2	A21	E	E	E	E	E	E	E	E	-5
3	B12	E	E	E	E	E	7	E	E	-1
4	B21	E	E	E	E	E	E	E	E	1
5	B23	E	E	E	E	E	E	E	E	-1
6	C24	E	E	E	E	E	E	E	E	-1
7	C26	E	E	E	E	E	E	E	E	1
8	C61	E	E	E	E	E	E	E	E	-1
9	D14	E	E	E	E	E	E	E	E	-1
10	D19	E	E	E	E	E	E	E	E	-5
11	D21	E	E	E	E	E	E	E	E	-5
12	D47	E	E	E	E	E	E	E	E	1
13	D81	E	E	E	E	E	E	E	E	1
14	D97	E	E	E	E	E	E	E	E	-1
15	D99	E	E	E	E	E	E	E	E	-1&lt;/PRE&gt;&lt;P&gt;As a note the true variable names are not in the form of V1, V87, but are more like first_name, Last_name, DOB, Gender...…&lt;/P&gt;&lt;P&gt;How can I achieve my wants using SAS?&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2018 14:42:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/499540#M132951</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2018-09-27T14:42:11Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Compare</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/499542#M132952</link>
      <description>Loop thru the dataset and drop any variables where the count=E is the same as the count of all records.</description>
      <pubDate>Thu, 27 Sep 2018 15:00:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/499542#M132952</guid>
      <dc:creator>tomrvincent</dc:creator>
      <dc:date>2018-09-27T15:00:57Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Compare</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/499565#M132958</link>
      <description>&lt;P&gt;I would start by following the proc compare code with something like this:&lt;/P&gt;
&lt;PRE&gt;ods select nlevels;
ods output nlevels= work.levelset;
proc freq data=&amp;amp;mydata._&amp;amp;mydata_new. nlevels;run;&lt;/PRE&gt;
&lt;P&gt;The output set will contain a variable TableVar with the name of the variable, Nlevels the number of levels of values for the variable, NMisslevels number of missing levels and NNonMISSLevels.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The variables with Nlevels =1 and NMissLevels=1 have all the values as equal. That would give you a data set to extract variable names from that do not match&lt;/P&gt;
&lt;PRE&gt;proc sql;
   select Tablevar into :KeepList separated by ' '
   from work.levelset
   where nlevels ne 1 or NmissLevels ne 1
   ;
quit;


data want;
   set &amp;amp;mydata._&amp;amp;mydata_new. (keep=&amp;amp;keeplist.);
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Sep 2018 15:57:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/499565#M132958</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-09-27T15:57:16Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Compare</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/499587#M132963</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt; this provide what I needed to achieve in my examples.&lt;/P&gt;&lt;P&gt;1 more Question is there an option for testing $ variables and if so what would that option be?&amp;nbsp; I have a few columns left over that are equal represented with dot dot (..).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2018 16:37:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/499587#M132963</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2018-09-27T16:37:12Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Compare</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/499645#M132987</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/122002"&gt;@VDD&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt; this provide what I needed to achieve in my examples.&lt;/P&gt;
&lt;P&gt;1 more Question is there an option for testing $ variables and if so what would that option be?&amp;nbsp; I have a few columns left over that are equal represented with dot dot (..).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The process works to identify variables with at least two values&amp;nbsp;in the data. If all of the character values are exactly the same the nlevels value should be 1 and the NNonMissLevels should be 1.&amp;nbsp; The difference is that the E that you see for numeric in the comparison output set is a special missing and for character number of . indicate the positions of matching characters, mismatched characters have an X&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2018 18:23:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/499645#M132987</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-09-27T18:23:59Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Compare</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/499903#M133060</link>
      <description>&lt;P&gt;Just for fun.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards expandtabs truncover;
input (Anumber	Bnumber	V1	V2	V3	V4	V5	V6	V7	V8	V87) ($);
cards;
1	A12	E	E	E	E	E	E	E	E	-1
2	A21	E	E	E	E	E	E	E	E	-5
3	B12	E	E	E	E	E	E	E	E	-1
4	B21	E	E	E	E	E	E	E	E	1
5	B23	E	E	E	E	E	E	E	E	-1
6	C24	E	E	E	E	E	E	E	E	-1
7	C26	E	E	E	E	E	E	E	E	1
8	C61	E	E	E	E	E	E	E	E	-1
9	D14	E	E	E	E	E	E	E	E	-1
10	D19	E	E	E	E	E	E	E	E	-5
11	D21	E	E	E	E	E	E	E	E	-5
12	D47	E	E	E	E	E	E	E	E	1
13	D81	E	E	E	E	E	E	E	E	1
14	D97	E	E	E	E	E	E	E	E	-1
15	D99	E	E	E	E	E	E	E	E	-1
;
run;
data _null_;
 set sashelp.vcolumn(where=(libname='WORK' and memname='HAVE')) end=last;
 if _n_=1 then call execute('proc sql;create table temp as select ');
 call execute(catx(' ','min(',name,')=max(',name,') as ',name));
 if last then call execute('from have;quit;');
  else call execute(',');
run;
proc transpose data=temp out=temp1;
run;
proc sql noprint;
 select _name_ into :keep separated by ' '
  from temp1
   where col1=0;
quit;
data want;
 set have;
 keep &amp;amp;keep;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Sep 2018 13:47:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/499903#M133060</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-09-28T13:47:59Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Compare</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/499908#M133062</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt; this also removes the $ columns with all equal. &amp;nbsp;&lt;/P&gt;&lt;P&gt;I should have asked about the $ to begin with but that was an oversight on my part.&lt;/P&gt;&lt;P&gt;I want to thank everyone for assisting with this task as it will make my work easier.&lt;/P&gt;&lt;P&gt;This was also a learning experience for me learning about the nlevels thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt; and all that contribute to the community links.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2018 14:09:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/499908#M133062</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2018-09-28T14:09:56Z</dc:date>
    </item>
  </channel>
</rss>

