<?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: Comparing same variable from two datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Comparing-same-variable-from-two-datasets/m-p/266225#M52440</link>
    <description>&lt;P&gt;My approach would depend on the characteristics of the two datasets and other circumstances:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Are the datasets sorted (or indexed) by ID?&lt;/LI&gt;
&lt;LI&gt;Are there (possibly) duplicate ID values in one or in both datasets?&lt;/LI&gt;
&lt;LI&gt;If so, how should these be counted if they match?&lt;/LI&gt;
&lt;LI&gt;Are there missing values of ID?&lt;/LI&gt;
&lt;LI&gt;How large are the datasets?&lt;/LI&gt;
&lt;LI&gt;Do they have other variables in common except ID?&lt;/LI&gt;
&lt;LI&gt;Is it a quick-and-dirty count for your own purposes or part of a production-level program?&lt;/LI&gt;
&lt;LI&gt;Shall the number of matching ID values be written to the log, the output window, a dataset, a macro variable, ...?&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;[Edit: inserted missing word in item 7]&lt;/P&gt;</description>
    <pubDate>Tue, 26 Apr 2016 09:18:35 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2016-04-26T09:18:35Z</dc:date>
    <item>
      <title>Comparing same variable from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-same-variable-from-two-datasets/m-p/266144#M52413</link>
      <description>&lt;P&gt;Hi SAS users,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two dataset which have one variable in common (ID). Now, I would like to simply compare this variable between these two datasets; and make sure how many observations of the common variable (ID) from the smaller dataset exist in the bigger dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used proc compare but I am not sure if its the best method. Please advise.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2016 18:08:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-same-variable-from-two-datasets/m-p/266144#M52413</guid>
      <dc:creator>almmotamedi</dc:creator>
      <dc:date>2016-04-25T18:08:51Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing same variable from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-same-variable-from-two-datasets/m-p/266146#M52414</link>
      <description>&lt;P&gt;It works. It depends on what you want as output and what meets your requirement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So what are your requirements besides what's in both? What do you plan to do with this information afterwards.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Personally I find proc compare a bit useless except for quick comparisons and generally write my own code for comparisons.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2016 18:11:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-same-variable-from-two-datasets/m-p/266146#M52414</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-25T18:11:44Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing same variable from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-same-variable-from-two-datasets/m-p/266148#M52415</link>
      <description>&lt;P&gt;what I want is just a simple comparison based on how many variable ID&amp;nbsp;is matched in both datasets. No specific requirement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2016 18:28:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-same-variable-from-two-datasets/m-p/266148#M52415</guid>
      <dc:creator>almmotamedi</dc:creator>
      <dc:date>2016-04-25T18:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing same variable from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-same-variable-from-two-datasets/m-p/266150#M52416</link>
      <description>&lt;P&gt;&lt;FONT color="#3366FF"&gt;DATA1:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp;A &amp;nbsp;B&lt;/P&gt;&lt;P&gt;8&amp;nbsp; &amp;nbsp; . &amp;nbsp; .&lt;/P&gt;&lt;P&gt;9&amp;nbsp; &amp;nbsp; . &amp;nbsp; .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;DATA2:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID C &amp;nbsp;D&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; 5 &amp;nbsp;6&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; 7 &amp;nbsp;8&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; 9 &amp;nbsp;3&lt;/P&gt;&lt;P&gt;4 &amp;nbsp; 6 &amp;nbsp;6&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;proc compare base = data1 compare=data2;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;var ID;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;with ID;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;run;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why after running the program, in the observation summary it says:&lt;/P&gt;&lt;P&gt;Number of Observations in Common:&amp;nbsp;2 &amp;nbsp;?!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Although, we don't have any common observation in varibale ID. Right?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&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>Mon, 25 Apr 2016 18:26:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-same-variable-from-two-datasets/m-p/266150#M52416</guid>
      <dc:creator>almmotamedi</dc:creator>
      <dc:date>2016-04-25T18:26:23Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing same variable from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-same-variable-from-two-datasets/m-p/266162#M52420</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/65070"&gt;@almmotamedi﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to use PROC COMPARE for this purpose (and not a data step with MERGE statement or PROC SQL), you should use the ID statement instead of the WITH statement.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2016 18:46:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-same-variable-from-two-datasets/m-p/266162#M52420</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-04-25T18:46:41Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing same variable from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-same-variable-from-two-datasets/m-p/266164#M52422</link>
      <description>&lt;P&gt;Thank you, but how using ID statement gives me observation summary? (I tried and it only gives variable summary!). Please help&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2016 19:17:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-same-variable-from-two-datasets/m-p/266164#M52422</guid>
      <dc:creator>almmotamedi</dc:creator>
      <dc:date>2016-04-25T19:17:13Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing same variable from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-same-variable-from-two-datasets/m-p/266165#M52423</link>
      <description>&lt;P&gt;Not quite right, but enough to get you started.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA data1;
 
input ID  A  B;
cards;
8    .   .
9    .   .
;
 
data DATA2;
 
input ID C  D;
cards;
1   5  6
2   7  8
3   9  3
4   6  6
;

proc sql;
create table want as
select coalesce(a.id,b.id) as ID, a.ID as ID1, b.ID as ID2,
	case when a.ID=. then 'Data1'
	     when b.ID=. then 'Data2'
		 else 'CHECKME' end as source
from data1 as a
full join data2 as b
on a.id=b.id;
quit;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Apr 2016 19:21:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-same-variable-from-two-datasets/m-p/266165#M52423</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-25T19:21:37Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing same variable from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-same-variable-from-two-datasets/m-p/266192#M52429</link>
      <description>&lt;P&gt;Thank you so much, your answered worked for the sample datasets. But when I applied the code for the real datasets, I received the error below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;ERROR: Expression using equals (=) has components that are of different data types.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for&amp;nbsp;&lt;FONT color="#0000FF"&gt;on a.id=b.id&lt;/FONT&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had checked the data types and both variables are character with the same length !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please advise?&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2016 20:13:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-same-variable-from-two-datasets/m-p/266192#M52429</guid>
      <dc:creator>almmotamedi</dc:creator>
      <dc:date>2016-04-25T20:13:54Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing same variable from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-same-variable-from-two-datasets/m-p/266196#M52431</link>
      <description>&lt;P&gt;Show us the proc contents results for the two sets that are involved in the error.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2016 20:19:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-same-variable-from-two-datasets/m-p/266196#M52431</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-04-25T20:19:43Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing same variable from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-same-variable-from-two-datasets/m-p/266206#M52432</link>
      <description>&lt;P&gt;I checked the results and everything is the same except in one dataset the variable has "format" and "informat", but the other does not.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/2912i64E5C4EE9513A6E4/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="1.jpg" title="1.jpg" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/2913i5FDDCFEA2B09714C/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="2.jpg" title="2.jpg" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2016 20:34:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-same-variable-from-two-datasets/m-p/266206#M52432</guid>
      <dc:creator>almmotamedi</dc:creator>
      <dc:date>2016-04-25T20:34:20Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing same variable from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-same-variable-from-two-datasets/m-p/266209#M52433</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/65070"&gt;@almmotamedi&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thank you, but how using ID statement gives me observation summary? (I tried and it only gives variable summary!). Please help&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This would be the case if you omitted the VAR statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My suggestion, however, was to "&lt;SPAN&gt;use the ID statement instead of the WITH statement."&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc compare base=data1 compare=data2;
var ID;
id ID;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;(But my first choice for this task would not be PROC COMPARE.)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2016 20:38:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-same-variable-from-two-datasets/m-p/266209#M52433</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-04-25T20:38:42Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing same variable from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-same-variable-from-two-datasets/m-p/266212#M52434</link>
      <description>&lt;P&gt;So, could you please advise how you would do it, this task seems to be very easy but I am still struggling to find an answer!&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2016 20:42:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-same-variable-from-two-datasets/m-p/266212#M52434</guid>
      <dc:creator>almmotamedi</dc:creator>
      <dc:date>2016-04-25T20:42:11Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing same variable from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-same-variable-from-two-datasets/m-p/266216#M52435</link>
      <description>&lt;P&gt;The error message from PROC SQL does not refer to the ON clause, but to the WHEN conditions where character ID's would not match the type of numeric missing values. Just replace the latter with character missings &lt;FONT face="courier new,courier"&gt;' '&lt;/FONT&gt; or use neutral conditions like&lt;/P&gt;
&lt;PRE&gt;when a.ID is null&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;PRE&gt;when missing(a.ID)&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Apr 2016 20:51:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-same-variable-from-two-datasets/m-p/266216#M52435</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-04-25T20:51:17Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing same variable from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-same-variable-from-two-datasets/m-p/266225#M52440</link>
      <description>&lt;P&gt;My approach would depend on the characteristics of the two datasets and other circumstances:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Are the datasets sorted (or indexed) by ID?&lt;/LI&gt;
&lt;LI&gt;Are there (possibly) duplicate ID values in one or in both datasets?&lt;/LI&gt;
&lt;LI&gt;If so, how should these be counted if they match?&lt;/LI&gt;
&lt;LI&gt;Are there missing values of ID?&lt;/LI&gt;
&lt;LI&gt;How large are the datasets?&lt;/LI&gt;
&lt;LI&gt;Do they have other variables in common except ID?&lt;/LI&gt;
&lt;LI&gt;Is it a quick-and-dirty count for your own purposes or part of a production-level program?&lt;/LI&gt;
&lt;LI&gt;Shall the number of matching ID values be written to the log, the output window, a dataset, a macro variable, ...?&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;[Edit: inserted missing word in item 7]&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2016 09:18:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-same-variable-from-two-datasets/m-p/266225#M52440</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-04-26T09:18:35Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing same variable from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-same-variable-from-two-datasets/m-p/266260#M52454</link>
      <description>Does SQL do this job ?

&lt;PRE&gt;
proc sql;
select id from small
intersect
select id from big;
quit;
&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Apr 2016 02:32:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-same-variable-from-two-datasets/m-p/266260#M52454</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-04-26T02:32:43Z</dc:date>
    </item>
  </channel>
</rss>

