<?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: How to find common values between two datasets? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-find-common-values-between-two-datasets/m-p/870512#M38533</link>
    <description>&lt;P&gt;Your title says "common values" but then your text asks for "common variable". Which is it? Could you explain further? Can you provide example data and example output?&lt;/P&gt;</description>
    <pubDate>Wed, 19 Apr 2023 10:07:26 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-04-19T10:07:26Z</dc:date>
    <item>
      <title>How to find common values between two datasets?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-find-common-values-between-two-datasets/m-p/870506#M38532</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I have imported a csv file in SAS and have a dataset. I want to compare both of them and find the common postcodes. What is the best way to do it? The imported file is elnz_lowell_12sep and the dataset name is Trace_results. The postcode header is&amp;nbsp;TA_PCODE. I have tried the proc compare step but I don't want the report. I want the table with common variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc compare base=work.elnz_lowell_12sep
Compare=Trace_result;
var TA_PCODE;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Apr 2023 09:28:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-find-common-values-between-two-datasets/m-p/870506#M38532</guid>
      <dc:creator>Sandeep77</dc:creator>
      <dc:date>2023-04-19T09:28:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to find common values between two datasets?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-find-common-values-between-two-datasets/m-p/870512#M38533</link>
      <description>&lt;P&gt;Your title says "common values" but then your text asks for "common variable". Which is it? Could you explain further? Can you provide example data and example output?&lt;/P&gt;</description>
      <pubDate>Wed, 19 Apr 2023 10:07:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-find-common-values-between-two-datasets/m-p/870512#M38533</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-19T10:07:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to find common values between two datasets?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-find-common-values-between-two-datasets/m-p/870523#M38534</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;As I said that I want to find out from TA_PCODE variable that how many of them are same.&lt;/P&gt;
&lt;P&gt;Sample data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data elnz_lowell_12sep;
input Reference_number	Add_line_1	Add_line_2	Add_line_	Add_line_4	TA_PCODE;
datalines;
24567456	23 Park Lane	High street	Bradford		BD7 1RE
24468265	81 Moudsley Streed		Leeds		LS12
56452464	49 laistridge lane		Manchester		M14 6PA
;
run;

Data Trace_result;
input Reference_number	Add_line_1	Add_line_2	Add_line_	Add_line_4	TA_PCODE;
datalines;
24567428	43 Roysdale road		London		L24 8PN
54468547	32 Merton Road		Leeds		LS110 1AB
56452464	49 laistridge lane		Manchester		M14 6PA
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Apr 2023 11:07:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-find-common-values-between-two-datasets/m-p/870523#M38534</guid>
      <dc:creator>Sandeep77</dc:creator>
      <dc:date>2023-04-19T11:07:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to find common values between two datasets?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-find-common-values-between-two-datasets/m-p/870591#M38552</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Example input data and expected results&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Apr 2023 16:02:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-find-common-values-between-two-datasets/m-p/870591#M38552</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-04-19T16:02:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to find common values between two datasets?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-find-common-values-between-two-datasets/m-p/870594#M38554</link>
      <description>&lt;P&gt;What exactly do you need to test?&amp;nbsp; You mentioned POSTCODE but your data seems to be based on REFERENCE_NUMBER.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If REFERENCE_NUMBER is a unique key in both datasets then here is a way to split the data into four datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data left right left_only right_only;
  set elnz_lowell_12sep(in=inleft) Trace_result(in=inright);
  by Reference_number ;
  if first.Reference_number	and last.Reference_numbe then do;
     if inleft then output left_only;
     else output right_only;
  end;
  else if inleft then output left;
  else output right;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can look a the LEFT_ONLY and RIGHT_ONLY datasets to see the reference numbers that show up in only one place.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use PROC COMPARE on the left and right datasets to see if any of the values of the other variables differ for the matching observations.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc compare data=left compare=right;
  id Reference_number;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Apr 2023 16:27:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-find-common-values-between-two-datasets/m-p/870594#M38554</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-19T16:27:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to find common values between two datasets?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-find-common-values-between-two-datasets/m-p/870597#M38555</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/391779"&gt;@Sandeep77&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;As I said that I want to find out from TA_PCODE variable that how many of them are same.&lt;/P&gt;
&lt;P&gt;Sample data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data elnz_lowell_12sep;
input Reference_number	Add_line_1	Add_line_2	Add_line_	Add_line_4	TA_PCODE;
datalines;
24567456	23 Park Lane	High street	Bradford		BD7 1RE
24468265	81 Moudsley Streed		Leeds		LS12
56452464	49 laistridge lane		Manchester		M14 6PA
;
run;

Data Trace_result;
input Reference_number	Add_line_1	Add_line_2	Add_line_	Add_line_4	TA_PCODE;
datalines;
24567428	43 Roysdale road		London		L24 8PN
54468547	32 Merton Road		Leeds		LS110 1AB
56452464	49 laistridge lane		Manchester		M14 6PA
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;These steps will only result in a lot of ERRORs and unusable datasets with missing numeric values. Please test and fix your codes before posting. It's not rocket science, you CAN do that.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Apr 2023 16:36:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-find-common-values-between-two-datasets/m-p/870597#M38555</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-04-19T16:36:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to find common values between two datasets?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-find-common-values-between-two-datasets/m-p/870599#M38556</link>
      <description>&lt;P&gt;If you want to compare the ta_pcode values for given reference_numbers, you need to do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=elnz_lowell_12sep;
by reference_number;
run;

proc sort data=trace_result;
by reference_number;
run;

proc compare
  base=elnz_lowell_12sep
  compare=trace_result
;
var ta_pcode;
id reference_number;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Apr 2023 16:44:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-find-common-values-between-two-datasets/m-p/870599#M38556</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-04-19T16:44:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to find common values between two datasets?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-find-common-values-between-two-datasets/m-p/870600#M38557</link>
      <description>&lt;P&gt;You really do need to clean up that data input. For simplicity I've dropped everything except the codes of interest.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data elnz_lowell_12sep;
infile cards dsd truncover;
input Reference_number TA_PCODE $;
cards;
24567456, BD7 1RE
24468265, LS12
56452464, M14 6PA
;
run;

Data Trace_result;
infile cards dsd truncover;
input Reference_number TA_PCODE $;
datalines;
24567428, L24 8PN
54468547, LS110 1AB
56452464, M14 6PA
;
run;

proc sort data=elnz_lowell_12sep(keep=ta_pcode) out=elnz nodupkey;
by ta_pcode;
run;

proc sort data=Trace_result(keep=ta_pcode) out=trace nodupkey;
by ta_pcode;
run;

data want;
merge elnz (in=_e) trace (in=_t);
by ta_pcode;

length status $15.;

if _e &amp;amp; _t then Status='Both';
else if _e then Status='ELNZ Only';
else if _t then Status = 'Trace Only';
 

run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Apr 2023 17:06:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-find-common-values-between-two-datasets/m-p/870600#M38557</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-04-19T17:06:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to find common values between two datasets?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-find-common-values-between-two-datasets/m-p/870649#M38558</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/391779"&gt;@Sandeep77&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;As I said that I want to find out from TA_PCODE variable that how many of them are same.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Do you want to know "how many are the same", a count, or the actual values that are the same, a data set with the codes in both?&lt;/P&gt;
&lt;P&gt;This does the latter:&lt;/P&gt;
&lt;PRE&gt;data set1;
  input code $;
datalines;
a
a
a
b
c
d
b
c
c
;

data set2;
  input code $;
datalines;
a
c
q
q
q
c
c
c
;

proc sql;
   create table commoncode as
   select distinct a.code
   from set1 as a 
        natural join
        set2 as b
   ;
quit;&lt;/PRE&gt;
&lt;P&gt;To find codes in Set1 but not Set2&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table in1_not2 a
   select distinct code from set1
   except
   select distinct code from set2
   ;
quit;&lt;/PRE&gt;
&lt;P&gt;You don't explicitly show what the expected result should look like.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/391779"&gt;@Sandeep77&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;As I said that I want to find out from TA_PCODE variable that how many of them are same.&lt;/P&gt;
&lt;P&gt;Sample data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data elnz_lowell_12sep;
input Reference_number	Add_line_1	Add_line_2	Add_line_	Add_line_4	TA_PCODE;
datalines;
24567456	23 Park Lane	High street	Bradford		BD7 1RE
24468265	81 Moudsley Streed		Leeds		LS12
56452464	49 laistridge lane		Manchester		M14 6PA
;
run;

Data Trace_result;
input Reference_number	Add_line_1	Add_line_2	Add_line_	Add_line_4	TA_PCODE;
datalines;
24567428	43 Roysdale road		London		L24 8PN
54468547	32 Merton Road		Leeds		LS110 1AB
56452464	49 laistridge lane		Manchester		M14 6PA
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Apr 2023 21:05:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-find-common-values-between-two-datasets/m-p/870649#M38558</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-04-19T21:05:04Z</dc:date>
    </item>
  </channel>
</rss>

