<?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/390474#M93672</link>
    <description>&lt;P&gt;Of course, but you need to define how, what are the rules that define what to be extracted. You haven't commented on the fact that the PROC COMPARE is wrong and that you don't know the difference. You don't know how many are in one and not the other, because you can have duplicates. If each data set has no duplicate records then you may be ok.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have no duplicates in either data set this approach may work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have1; by ID_VAR;
proc sort data=have2; by ID_VAR;

data both /*includes records from both datasets*/
        in1 /*records only in have1*/
       in2 /*records only in have2*/;
merge have1 (in=a)
           have2 (in=b);

by ID_VAR;

if a and b then output both;
if a and not b then output in1;
if b and not a then output in2;

run;



&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 24 Aug 2017 01:28:29 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-08-24T01:28:29Z</dc:date>
    <item>
      <title>Proc Compare</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/390079#M93540</link>
      <description>&lt;P&gt;I am comparing two datasets, say A and B.&lt;/P&gt;
&lt;P&gt;My SAS code is :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc compare base=N_402612(Keep=receipt ) compare=N_389132(Keep=receipt ) out=check ;
run;&lt;/PRE&gt;
&lt;P&gt;LOG:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;23         GOPTIONS ACCESSIBLE;
24         	
24       !  proc compare base=N_402612(Keep=receipt ) compare=N_389132(Keep=receipt ) out=check  ;
25         
26         	run;

NOTE: There were 402612 observations read from the data set WORK.N_402612.
NOTE: There were 389132 observations read from the data set WORK.N_389132.
NOTE: The data set WORK.CHECK has 389132 observations and 3 variables.&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;                                                                                                                                    
                                                                                                                                    
Observation Summary                                                                                                                 
                                                                                                                                    
Observation      Base  Compare                                                                                                      
                                                                                                                                    
First Obs           1        1                                                                                                      
First Unequal       9        9                                                                                                      
Last  Unequal  389132   389132                                                                                                      
Last  Match    389132   389132                                                                                                      
Last  Obs      402612        .                                                                                                      
                                                                                                                                    
Number of Observations in Common: 389132.                                                                                           
Number of Observations in WORK.N_402612 but not in WORK.N_389132: 13480.                                                            
Total Number of Observations Read from WORK.N_402612: 402612.                                                                       
Total Number of Observations Read from WORK.N_389132: 389132.                                                                       
                                                                                                                                    
Number of Observations with Some Compared Variables Unequal: 389124.                                                                
Number of Observations with All Compared Variables Equal: 8.                                                                        
                                                                                                                                    
                                                                                                                                    
Values Comparison Summary                                                                                                           
                                                                                                                                    
Number of Variables Compared with All Observations Equal: 0.                                                                        
Number of Variables Compared with Some Observations Unequal: 1.                                                                     
Total Number of Values which Compare Unequal: 389124.                                                                               
                                                                                                                                    
                                                                                                                                    
All Variables Compared have Unequal Values                                                                                          
                                                                                                                                    
Variable  Type  Len   Label          Ndif   MaxDif                                                                                  
                                                                                                                                    
Receipt   CHAR   13   Recipt Number389124                                                                                           
                                                                                                                                    
 &lt;/PRE&gt;
&lt;P&gt;In the output dataset Check, I want to keep only n=13480 records in my output dataset check.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Number of Observations in WORK.N_402612 but not in WORK.N_389132: 13480.                                                            							
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2017 02:19:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/390079#M93540</guid>
      <dc:creator>GPatel</dc:creator>
      <dc:date>2017-08-23T02:19:03Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Compare</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/390100#M93553</link>
      <description>&lt;P&gt;An SQL query to do that is likely easier than trying to get the numbers out of PROC COMPARE. Otherwise look at the OUTDIFF data set.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2017 04:21:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/390100#M93553</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-23T04:21:42Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Compare</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/390101#M93554</link>
      <description>Also, note that value is the difference, it did a line by line comparison when I suspect you're trying to check for a specific variable. You need to add that option to proc compare, I think it's a VAR statement or ID statement.</description>
      <pubDate>Wed, 23 Aug 2017 04:22:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/390101#M93554</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-23T04:22:44Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Compare</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/390105#M93556</link>
      <description>&lt;P&gt;You want to only keep 10,000 records? Which ones?&lt;/P&gt;
&lt;P&gt;How does proc compare know?&lt;/P&gt;
&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;said, you probably need a key (an ID statement in proc compare, or another join like a proc sql) to give some sense to your comparison.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2017 04:33:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/390105#M93556</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-08-23T04:33:34Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Compare</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/390174#M93566</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your insight and suggested solution. Proc SQL and Data Merge doesn't give me correct/exact counts. I need to&amp;nbsp;&lt;/P&gt;
&lt;P&gt;create a SAS dataset of n=13,480 records as outlined by Proc Compare results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Number of Observations in WORK.N_402612 but not in WORK.N_389132: 13480.&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; I hope somebody will shed some lights and offers desired solution.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2017 10:52:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/390174#M93566</guid>
      <dc:creator>GPatel</dc:creator>
      <dc:date>2017-08-23T10:52:05Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Compare</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/390273#M93588</link>
      <description>Your PROC COMPARE is wrong, so expecting that number in the first place is wrong.</description>
      <pubDate>Wed, 23 Aug 2017 14:43:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/390273#M93588</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-23T14:43:49Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Compare</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/390449#M93661</link>
      <description>&lt;P&gt;Let's try another way.&lt;/P&gt;
&lt;P&gt;What don't you just look at the first&amp;nbsp;&lt;SPAN&gt;13,480 records? or the the last 13,480 records?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Why not? How do *you* know these are not the ones you are after?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2017 23:00:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/390449#M93661</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-08-23T23:00:06Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Compare</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/390457#M93665</link>
      <description>&lt;P&gt;&lt;FONT face="courier new,courier"&gt;these papers &lt;/FONT&gt;describes&lt;FONT face="courier new,courier"&gt; macros that may have hints to what you want to do.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;A href="http://www.sascommunity.org/wiki/Macro_ComparWS_Compare_with_summary" target="_blank"&gt;http://www.sascommunity.org/wiki/Macro_ComparWS_Compare_with_summary&lt;/A&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;A href="http://www.sascommunity.org/wiki/Macro_Extract" target="_blank"&gt;http://www.sascommunity.org/wiki/Macro_Extract&lt;/A&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Ron Fehd&amp;nbsp; comparatively, a maven&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2017 23:16:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/390457#M93665</guid>
      <dc:creator>Ron_MacroMaven</dc:creator>
      <dc:date>2017-08-23T23:16:40Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Compare</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/390460#M93666</link>
      <description>I did try it. No luck.&lt;BR /&gt;Is there any way to isolate only n=13,480 records?&lt;BR /&gt;</description>
      <pubDate>Wed, 23 Aug 2017 23:21:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/390460#M93666</guid>
      <dc:creator>GPatel</dc:creator>
      <dc:date>2017-08-23T23:21:01Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Compare</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/390474#M93672</link>
      <description>&lt;P&gt;Of course, but you need to define how, what are the rules that define what to be extracted. You haven't commented on the fact that the PROC COMPARE is wrong and that you don't know the difference. You don't know how many are in one and not the other, because you can have duplicates. If each data set has no duplicate records then you may be ok.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have no duplicates in either data set this approach may work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have1; by ID_VAR;
proc sort data=have2; by ID_VAR;

data both /*includes records from both datasets*/
        in1 /*records only in have1*/
       in2 /*records only in have2*/;
merge have1 (in=a)
           have2 (in=b);

by ID_VAR;

if a and b then output both;
if a and not b then output in1;
if b and not a then output in2;

run;



&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Aug 2017 01:28:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/390474#M93672</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-24T01:28:29Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Compare</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/390480#M93674</link>
      <description>&lt;P&gt;Interesting.&amp;nbsp; There is a LISTBASEOBS options which will list the records in the base dataset only, but I don't see an OUTBASEOBS option that would output those records.&amp;nbsp; So I'm going to go out on a limb and say no, PROC COMPARE can't do it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But do note the point made above by&amp;nbsp;many folks.&amp;nbsp; Right now you are doing a one-to-one&amp;nbsp;sequential comparison (first record of each dataset&amp;nbsp;is compared, then second record of each, etc.)&amp;nbsp; When you compare N_402612 to N_389132, the 13,480 records reported as being in N_402612&amp;nbsp;are simply the last 13,480 records from N_402612 .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are doing the equivalent of:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc compare base=sashelp.class compare=sashelp.class(obs=10) ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which will report a difference of 9 records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you really want the last 13,480 records from N_402612&amp;nbsp;you can get them like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set N_402612(firstobs=%eval(402612-13479));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Aug 2017 01:55:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/390480#M93674</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2017-08-24T01:55:25Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Compare</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/390486#M93678</link>
      <description>&lt;P&gt;Or maybe you just want:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select * from TAB1&amp;nbsp;
except&amp;nbsp;
select * from TAB2;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;from the paucity of your explanations, it is hard to guess what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Aug 2017 03:19:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/390486#M93678</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-08-24T03:19:56Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Compare</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/390869#M93822</link>
      <description>&lt;P&gt;Well, very good responses &amp;nbsp;recieved from&amp;nbsp;Reeza, ChrisNZ, Ron_Fehd_macro_maven, and &amp;nbsp;Quentin.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Each of them shed very intereting insights and comments.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It was found that&amp;nbsp;my dataset &amp;nbsp;A has n=xxxx,xxxx number of UNIQUE records not observed in dataset B. Similarly, dataset B has n=xxx,xxx&amp;nbsp;number of Unique records not observed in dataset A.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, I learned that Proc Compare should not be employed, but data step or SQL is a best solution. Case closed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks to all&amp;nbsp;who have responded.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Girish Patel&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2017 10:33:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/390869#M93822</guid>
      <dc:creator>GPatel</dc:creator>
      <dc:date>2017-08-25T10:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Compare</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/390933#M93840</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16940"&gt;@GPatel&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, I learned that Proc Compare should not be employed, but data step or SQL is a best solution. Case closed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That's not correct. You can use PROC COMPARE, but you were not using it correctly. You misinterpreted the results because you didn't have a BY or ID or VAR/WITH statements.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2017 15:09:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Compare/m-p/390933#M93840</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-25T15:09:33Z</dc:date>
    </item>
  </channel>
</rss>

