<?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: Simple Match-NoMatch Counts for Character Variables Using PROC COMPARE? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Simple-Match-NoMatch-Counts-for-Character-Variables-Using-PROC/m-p/334543#M62879</link>
    <description>&lt;P&gt;You could do it all with one proc compare, combined with a proc freq to analyze the results. e.g.,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data one;
  set sashelp.class;
  idnum=_n_;
run;

data two;
  retain height sex weight name age;
  set sashelp.class;
  idnum=_n_;
  if mod(_n_,2) then do;
    name='Ralph';
    sex='N';
    age=6;
    height=12;
    weight=74;
  end;
run;

proc compare base=one compare=two out=ds nosummary outdiff stats nomiss;
   id idnum;
run;

data ds;
  set ds;
  array chars _character_;
  array nums _numeric_;
  do over chars;
    if index(chars,'X') then chars='0';
    else chars=1;
  end;
  do over nums;
    if nums=0 then nums=1;
    else nums=0;
  end;
run;

proc freq data=ds;
  tables name--weight;
run;
&lt;/PRE&gt;
&lt;P&gt;Of course, you could add two formats if you want the output to be more descriptive.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 21 Feb 2017 02:59:28 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2017-02-21T02:59:28Z</dc:date>
    <item>
      <title>Simple Match-NoMatch Counts for Character Variables Using PROC COMPARE?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Simple-Match-NoMatch-Counts-for-Character-Variables-Using-PROC/m-p/334512#M62872</link>
      <description>&lt;P&gt;I have two datasets with over 1,000 &lt;STRONG&gt;character&lt;/STRONG&gt; variables in common between them. &amp;nbsp;I would like to get a simple count for each of these character variables showing the number of observations that match and the number of observations that don't match. &amp;nbsp;Something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Variable &amp;nbsp;Match &amp;nbsp;NoMatch&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;v1 &amp;nbsp; &amp;nbsp; &amp;nbsp;100 &amp;nbsp; &amp;nbsp; &amp;nbsp;10&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;v2 &amp;nbsp; &amp;nbsp; &amp;nbsp; 50 &amp;nbsp; &amp;nbsp; &amp;nbsp;60&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;v3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; 110&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; .&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; .&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; .&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="helvetica"&gt;&lt;SPAN&gt;If I could output the match-nomatch counts to a SAS dataset that would be even better.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="helvetica"&gt;&lt;SPAN&gt;The datasets also have a lot of numeric variables in common between them. &amp;nbsp;I already was able to do a suitable comparison using PROC COMPARE for the numeric variables as follows:&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="helvetica"&gt;&lt;SPAN&gt;proc compare base=ds_old&amp;nbsp;compare=ds_new outstats=ds_stats nosummary allstats novalues nomiss;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;id idnum;&lt;BR /&gt;run;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="helvetica"&gt;&lt;SPAN&gt;Want to do the something similar for all the character variables.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="helvetica"&gt;&lt;SPAN&gt;Thanks much,&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="helvetica"&gt;&lt;SPAN&gt;Dave&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2017 00:30:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Simple-Match-NoMatch-Counts-for-Character-Variables-Using-PROC/m-p/334512#M62872</guid>
      <dc:creator>doesper</dc:creator>
      <dc:date>2017-02-21T00:30:16Z</dc:date>
    </item>
    <item>
      <title>Re: Simple Match-NoMatch Counts for Character Variables Using PROC COMPARE?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Simple-Match-NoMatch-Counts-for-Character-Variables-Using-PROC/m-p/334538#M62877</link>
      <description>&lt;P&gt;PROC COMPARE doesn't limit to numeric variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think it's best if you post sample data that we can work with and expected output that matches your sample data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2017 02:35:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Simple-Match-NoMatch-Counts-for-Character-Variables-Using-PROC/m-p/334538#M62877</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-02-21T02:35:51Z</dc:date>
    </item>
    <item>
      <title>Re: Simple Match-NoMatch Counts for Character Variables Using PROC COMPARE?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Simple-Match-NoMatch-Counts-for-Character-Variables-Using-PROC/m-p/334542#M62878</link>
      <description>&lt;PRE&gt;
Can you post some sample data to describe your problem.
It is easy for IML code.


data old;
 set sashelp.class;
run;
data new;
 set sashelp.class;
 if _n_=1 then sex='X';
 if _n_=4 then name='KSharp';
run;
proc iml;
use old nobs nobs;
read all var _char_ into old[c=vname];
close;

use new;
read all var _char_ into new;
close;
var=t(vname);
match=t((old=new)[+,]);
not_match=t(nobs-match);

create want var {var match not_match};
append;
close;
quit;

&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Feb 2017 02:58:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Simple-Match-NoMatch-Counts-for-Character-Variables-Using-PROC/m-p/334542#M62878</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-02-21T02:58:58Z</dc:date>
    </item>
    <item>
      <title>Re: Simple Match-NoMatch Counts for Character Variables Using PROC COMPARE?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Simple-Match-NoMatch-Counts-for-Character-Variables-Using-PROC/m-p/334543#M62879</link>
      <description>&lt;P&gt;You could do it all with one proc compare, combined with a proc freq to analyze the results. e.g.,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data one;
  set sashelp.class;
  idnum=_n_;
run;

data two;
  retain height sex weight name age;
  set sashelp.class;
  idnum=_n_;
  if mod(_n_,2) then do;
    name='Ralph';
    sex='N';
    age=6;
    height=12;
    weight=74;
  end;
run;

proc compare base=one compare=two out=ds nosummary outdiff stats nomiss;
   id idnum;
run;

data ds;
  set ds;
  array chars _character_;
  array nums _numeric_;
  do over chars;
    if index(chars,'X') then chars='0';
    else chars=1;
  end;
  do over nums;
    if nums=0 then nums=1;
    else nums=0;
  end;
run;

proc freq data=ds;
  tables name--weight;
run;
&lt;/PRE&gt;
&lt;P&gt;Of course, you could add two formats if you want the output to be more descriptive.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2017 02:59:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Simple-Match-NoMatch-Counts-for-Character-Variables-Using-PROC/m-p/334543#M62879</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-21T02:59:28Z</dc:date>
    </item>
    <item>
      <title>Re: Simple Match-NoMatch Counts for Character Variables Using PROC COMPARE?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Simple-Match-NoMatch-Counts-for-Character-Variables-Using-PROC/m-p/334732#M62902</link>
      <description>&lt;P&gt;Thanks to Reeza, Ksharp, and Art297 for responding. &amp;nbsp;With regards to Ksharp's suggestion about using IML - wish we had it but we don't. &amp;nbsp;Perhaps IML will someday be included with&amp;nbsp;SAS Foundation? &amp;nbsp;Here's hoping...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the end, I went with a variant of what Art297 suggested. &amp;nbsp;Here's what I did. &amp;nbsp;Not elegant, but it does get the job done.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks to all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dave&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc compare base=ds_old compare=ds_new out=ds_stats2 outdif noprint;
   id idnum;
   var _character_;
run;

data ds_stats2b;
   set ds_stats2;
   array chars _character_;
   do over chars;
      if index(chars,'X') then chars = '0';
      else                     chars = '1';
   end;
run;

ods output OneWayFreqs = ds_stats2c;
proc freq data=ds_stats2b;
  tables _character_;
run;
ods output close;

data ds_stats2d;
   set ds_stats2c;
   where round(cumpercent,.01) &amp;lt; 100.00;
   element = substr(table,7);
   pctdiff = percent;
   keep element pctdiff;
run;

proc sort data=ds_stats2d;
   by descending pctdiff;
run;

proc print data=ds_stats2d (obs=2000);
   title 'ds_stats2d';
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Feb 2017 18:05:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Simple-Match-NoMatch-Counts-for-Character-Variables-Using-PROC/m-p/334732#M62902</guid>
      <dc:creator>doesper</dc:creator>
      <dc:date>2017-02-21T18:05:41Z</dc:date>
    </item>
  </channel>
</rss>

