<?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 Checking if value of one row in one dataset exists in one row of other dataset by ID in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-value-of-one-row-in-one-dataset-exists-in-one-row-of/m-p/286073#M58603</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am trying to see if values from one row of a certain ID group exists in a row of another dataset by the same ID group. the IDs are unique.&lt;/P&gt;
&lt;P&gt;I have two tables:&lt;/P&gt;
&lt;P&gt;Table 1: &lt;STRONG&gt;Estimates&lt;/STRONG&gt;&lt;/P&gt;
&lt;TABLE width="320" style="width: 240pt; border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL width="64" style="width: 48pt;" span="5" /&gt;&lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD width="64" height="17" style="border: 0px black; border-image: none; width: 48pt; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;ID&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border: 0px black; border-image: none; width: 48pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;ans1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border: 0px black; border-image: none; width: 48pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;ans2&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border: 0px black; border-image: none; width: 48pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;ans3&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border: 0px black; border-image: none; width: 48pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;ans4&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" style="border: 0px black; border-image: none; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;A1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;8&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;15&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;40&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;30&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" style="border: 0px black; border-image: none; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;A2&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;9&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;10&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;11&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;46&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" style="border: 0px black; border-image: none; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;A3&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;38&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;39&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;40&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;42&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" style="border: 0px black; border-image: none; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;A4&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;5&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;25&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;35&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;41&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;Table 2: &lt;STRONG&gt;Reference&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="320" style="width: 240pt; border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL width="64" style="width: 48pt;" span="5" /&gt;&lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD width="64" height="17" style="border: 0px black; border-image: none; width: 48pt; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;ID&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border: 0px black; border-image: none; width: 48pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;col1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border: 0px black; border-image: none; width: 48pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;col2&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border: 0px black; border-image: none; width: 48pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;col3&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border: 0px black; border-image: none; width: 48pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;col4&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" style="border: 0px black; border-image: none; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;A1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;5&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;15&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;20&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;40&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" style="border: 0px black; border-image: none; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;A2&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;11&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;12&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;13&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;37&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" style="border: 0px black; border-image: none; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;A3&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;38&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;39&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;40&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;42&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" style="border: 0px black; border-image: none; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;A4&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;5&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;25&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;35&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;41&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to get the following table (0 marks the point where the values match) eg: the code should check&amp;nbsp;for&amp;nbsp;all variables (where ID=A1)&amp;nbsp;in table1: estimates &lt;STRONG&gt;match&lt;/STRONG&gt; against all variables in table 2 (ID=A1): reference. If any value in table 1: estimates match with the same ID from table 2: then the matched variable, should be marked with 0.&lt;/P&gt;
&lt;P&gt;Table: &lt;STRONG&gt;want&lt;/STRONG&gt; mentioned below: (the&amp;nbsp;0 means that the values match)&lt;/P&gt;
&lt;TABLE width="320" style="width: 240pt; border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL width="64" style="width: 48pt;" span="4" /&gt;&lt;/COLGROUP&gt;&lt;COLGROUP&gt;&lt;COL width="64" style="width: 48pt;" /&gt;&lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD width="64" height="17" style="border: 0px black; border-image: none; width: 48pt; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;ID&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border: 0px black; border-image: none; width: 48pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;match1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border: 0px black; border-image: none; width: 48pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;match2&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border: 0px black; border-image: none; width: 48pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;match3&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border: 0px black; border-image: none; width: 48pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;match4&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" style="border: 0px black; border-image: none; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;A1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;0&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;0&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;1&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" style="border: 0px black; border-image: none; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;A2&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;0&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;1&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" style="border: 0px black; border-image: none; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;A3&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;0&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;0&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;0&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;0&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" style="border: 0px black; border-image: none; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;A4&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;0&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;0&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;0&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;0&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have adoped this code from a similar code written by Kshap earlier, but could not change it to suit my needs.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data reference;
input id $ col1 col2 col3 col4;
datalines;
A1 5 15 20 40
A2 11 12 13 37
A3 38 39 40 42
A4 5 25 35 41 
;

data estimates;
input id $ ans1 ans2 ans3 ans4;
datalines;
A1 8 15 40 30
A2 9 10 11 46
A3 38 39 40 42
A4 5 25 35 41 
;


data hash(keep=id val);
 set reference;
 array c{*} col: ;
 do i=1 to dim(c);
  val=c{i};if not missing(val) then output;
 end;
run;
proc sql ;
select distinct id  into : list separated by ' ' from reference;
quit;
data want (drop=i j k rc val id);
 if _n_ eq 1 then do;
  if 0 then set hash;
  declare hash ha(dataset:'hash');
   ha.definekey('val');
   ha.definedata('id');
   ha.definedone();
end;
set estimates;
by id;
array g{*} &amp;amp;list.;
array v{*} ans: ;
do k=1 to dim(g);
 g{k}=0;
end;
do i=1 to dim(v);
 val=v{i};
rc=ha.find();
 if rc=0 then do;
  do j=1 to dim(g);
	if id=vname(g{j}) then g{j}=1;
  end;
 end;
end;
run;





&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please help me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks.&lt;/P&gt;
&lt;P&gt;regards,&lt;/P&gt;
&lt;P&gt;Sebastian&lt;/P&gt;</description>
    <pubDate>Thu, 21 Jul 2016 10:30:50 GMT</pubDate>
    <dc:creator>sebster24</dc:creator>
    <dc:date>2016-07-21T10:30:50Z</dc:date>
    <item>
      <title>Checking if value of one row in one dataset exists in one row of other dataset by ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-value-of-one-row-in-one-dataset-exists-in-one-row-of/m-p/286073#M58603</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am trying to see if values from one row of a certain ID group exists in a row of another dataset by the same ID group. the IDs are unique.&lt;/P&gt;
&lt;P&gt;I have two tables:&lt;/P&gt;
&lt;P&gt;Table 1: &lt;STRONG&gt;Estimates&lt;/STRONG&gt;&lt;/P&gt;
&lt;TABLE width="320" style="width: 240pt; border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL width="64" style="width: 48pt;" span="5" /&gt;&lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD width="64" height="17" style="border: 0px black; border-image: none; width: 48pt; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;ID&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border: 0px black; border-image: none; width: 48pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;ans1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border: 0px black; border-image: none; width: 48pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;ans2&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border: 0px black; border-image: none; width: 48pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;ans3&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border: 0px black; border-image: none; width: 48pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;ans4&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" style="border: 0px black; border-image: none; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;A1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;8&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;15&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;40&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;30&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" style="border: 0px black; border-image: none; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;A2&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;9&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;10&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;11&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;46&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" style="border: 0px black; border-image: none; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;A3&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;38&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;39&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;40&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;42&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" style="border: 0px black; border-image: none; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;A4&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;5&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;25&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;35&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;41&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;Table 2: &lt;STRONG&gt;Reference&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="320" style="width: 240pt; border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL width="64" style="width: 48pt;" span="5" /&gt;&lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD width="64" height="17" style="border: 0px black; border-image: none; width: 48pt; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;ID&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border: 0px black; border-image: none; width: 48pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;col1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border: 0px black; border-image: none; width: 48pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;col2&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border: 0px black; border-image: none; width: 48pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;col3&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border: 0px black; border-image: none; width: 48pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;col4&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" style="border: 0px black; border-image: none; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;A1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;5&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;15&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;20&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;40&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" style="border: 0px black; border-image: none; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;A2&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;11&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;12&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;13&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;37&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" style="border: 0px black; border-image: none; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;A3&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;38&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;39&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;40&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;42&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" style="border: 0px black; border-image: none; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;A4&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;5&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;25&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;35&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;41&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to get the following table (0 marks the point where the values match) eg: the code should check&amp;nbsp;for&amp;nbsp;all variables (where ID=A1)&amp;nbsp;in table1: estimates &lt;STRONG&gt;match&lt;/STRONG&gt; against all variables in table 2 (ID=A1): reference. If any value in table 1: estimates match with the same ID from table 2: then the matched variable, should be marked with 0.&lt;/P&gt;
&lt;P&gt;Table: &lt;STRONG&gt;want&lt;/STRONG&gt; mentioned below: (the&amp;nbsp;0 means that the values match)&lt;/P&gt;
&lt;TABLE width="320" style="width: 240pt; border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL width="64" style="width: 48pt;" span="4" /&gt;&lt;/COLGROUP&gt;&lt;COLGROUP&gt;&lt;COL width="64" style="width: 48pt;" /&gt;&lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD width="64" height="17" style="border: 0px black; border-image: none; width: 48pt; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;ID&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border: 0px black; border-image: none; width: 48pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;match1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border: 0px black; border-image: none; width: 48pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;match2&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border: 0px black; border-image: none; width: 48pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;match3&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border: 0px black; border-image: none; width: 48pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;match4&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" style="border: 0px black; border-image: none; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;A1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;0&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;0&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;1&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" style="border: 0px black; border-image: none; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;A2&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;0&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;1&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" style="border: 0px black; border-image: none; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;A3&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;0&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;0&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;0&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;0&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" style="border: 0px black; border-image: none; height: 12.75pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;A4&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;0&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;0&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;0&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Arial" size="2"&gt;0&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have adoped this code from a similar code written by Kshap earlier, but could not change it to suit my needs.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data reference;
input id $ col1 col2 col3 col4;
datalines;
A1 5 15 20 40
A2 11 12 13 37
A3 38 39 40 42
A4 5 25 35 41 
;

data estimates;
input id $ ans1 ans2 ans3 ans4;
datalines;
A1 8 15 40 30
A2 9 10 11 46
A3 38 39 40 42
A4 5 25 35 41 
;


data hash(keep=id val);
 set reference;
 array c{*} col: ;
 do i=1 to dim(c);
  val=c{i};if not missing(val) then output;
 end;
run;
proc sql ;
select distinct id  into : list separated by ' ' from reference;
quit;
data want (drop=i j k rc val id);
 if _n_ eq 1 then do;
  if 0 then set hash;
  declare hash ha(dataset:'hash');
   ha.definekey('val');
   ha.definedata('id');
   ha.definedone();
end;
set estimates;
by id;
array g{*} &amp;amp;list.;
array v{*} ans: ;
do k=1 to dim(g);
 g{k}=0;
end;
do i=1 to dim(v);
 val=v{i};
rc=ha.find();
 if rc=0 then do;
  do j=1 to dim(g);
	if id=vname(g{j}) then g{j}=1;
  end;
 end;
end;
run;





&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please help me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks.&lt;/P&gt;
&lt;P&gt;regards,&lt;/P&gt;
&lt;P&gt;Sebastian&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2016 10:30:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-value-of-one-row-in-one-dataset-exists-in-one-row-of/m-p/286073#M58603</guid>
      <dc:creator>sebster24</dc:creator>
      <dc:date>2016-07-21T10:30:50Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if value of one row in one dataset exists in one row of other dataset by ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-value-of-one-row-in-one-dataset-exists-in-one-row-of/m-p/286075#M58604</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro match;

    data want;
        merge reference estimates;
        by id;
        %do i=1 %to 4;
            match&amp;amp;i.=(col&amp;amp;i. ne ans&amp;amp;i.);
        %end;

    run;

%mend;

%match;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Jul 2016 10:38:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-value-of-one-row-in-one-dataset-exists-in-one-row-of/m-p/286075#M58604</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2016-07-21T10:38:10Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if value of one row in one dataset exists in one row of other dataset by ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-value-of-one-row-in-one-dataset-exists-in-one-row-of/m-p/286080#M58606</link>
      <description>&lt;P&gt;I don't have the tine to spell it out right now, but the program would be short:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(1) merge the data sets by ID&lt;/P&gt;
&lt;P&gt;(2) set up arrays for the two sets of variables&lt;/P&gt;
&lt;P&gt;(3) move through the ANS array, using the WHICHN function against the MATCH array&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All told, maybe 10 lines of code.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2016 11:33:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-value-of-one-row-in-one-dataset-exists-in-one-row-of/m-p/286080#M58606</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-07-21T11:33:42Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if value of one row in one dataset exists in one row of other dataset by ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-value-of-one-row-in-one-dataset-exists-in-one-row-of/m-p/286085#M58609</link>
      <description>&lt;P&gt;expanding&amp;nbsp; gamotte's code just a little bit to test all 4 ans:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;%macro&lt;/SPAN&gt; match&lt;SPAN&gt;;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN&gt;data&lt;/SPAN&gt; want&lt;SPAN&gt;;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN&gt;merge&lt;/SPAN&gt; reference estimates&lt;SPAN&gt;;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN&gt;by&lt;/SPAN&gt; &lt;SPAN&gt;id&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &lt;SPAN&gt;%do&lt;/SPAN&gt; i&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt; &lt;SPAN&gt;%to&lt;/SPAN&gt; &lt;SPAN&gt;4&lt;/SPAN&gt;&lt;SPAN&gt;; &lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;test=0; match%i.=1; &lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN&gt;%do&lt;/SPAN&gt; x&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt; &lt;SPAN&gt;%to&lt;/SPAN&gt; &lt;SPAN&gt;4&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; test&lt;SPAN&gt;+(&lt;/SPAN&gt;col&lt;SPAN&gt;&amp;amp;&lt;/SPAN&gt;i&lt;SPAN&gt;.&lt;/SPAN&gt; &lt;SPAN&gt;ne&lt;/SPAN&gt; ans&lt;SPAN&gt;&amp;amp;x&lt;/SPAN&gt;&lt;SPAN&gt;.);&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;SPAN&gt;%end&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if test lt 4 then &lt;/SPAN&gt;match&lt;SPAN&gt;&amp;amp;&lt;/SPAN&gt;i&lt;SPAN&gt;.=0; &lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;%end&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &lt;SPAN&gt;run&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;SPAN&gt;%mend&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%match&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2016 11:58:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-value-of-one-row-in-one-dataset-exists-in-one-row-of/m-p/286085#M58609</guid>
      <dc:creator>Jim_G</dc:creator>
      <dc:date>2016-07-21T11:58:47Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if value of one row in one dataset exists in one row of other dataset by ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-value-of-one-row-in-one-dataset-exists-in-one-row-of/m-p/286087#M58610</link>
      <description>&lt;P&gt;Hello Gamotte,&lt;/P&gt;
&lt;P&gt;Thank you very much for your quick response &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The solution that you provided did not provide the exact answer as i wanted.&lt;/P&gt;
&lt;P&gt;However,&amp;nbsp;I have adopted your methodology and made a slight iteration myself:&lt;/P&gt;
&lt;P&gt;For anyone reading through the forum, code as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop= i j);
	merge reference estimates;
	by id;
	array ia{*}  ans:;
	array ja{*}  col:;
	array match{4} match1 match2 match3 match4;
	do i=1 to dim(ia);
		do j=1 to dim(ja);
			if  ja{j}= ia{i} then do;
				match{i} = 0;
			end;
		end;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Once again, thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2016 12:01:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-value-of-one-row-in-one-dataset-exists-in-one-row-of/m-p/286087#M58610</guid>
      <dc:creator>sebster24</dc:creator>
      <dc:date>2016-07-21T12:01:53Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if value of one row in one dataset exists in one row of other dataset by ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-value-of-one-row-in-one-dataset-exists-in-one-row-of/m-p/286088#M58611</link>
      <description>&lt;P&gt;Why do you need the macro code? &amp;nbsp;Base SAS can handle this just fine:&lt;/P&gt;
&lt;PRE&gt;data want;
  merge reference estimates;
  by id;
  array match{4} col{4} ans{4};
  do i=1 to 4;
    match{i}=(col{i} ne ans{i});
  end;
run;&lt;/PRE&gt;
&lt;P&gt;I can't check the code as in meeting, but that should be it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just to add, if you had your data in a strcuture which is more beneficial to the programming side of things (you can transpose for output) e.g.:&lt;/P&gt;
&lt;P&gt;SEQ &amp;nbsp; &amp;nbsp; ANS&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;abc&lt;/P&gt;
&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;def&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;Same for the other datasets, then merge by SEQ as well, then your code becomes even more simple and easy to maintain:&lt;/P&gt;
&lt;PRE&gt;data want;
  merge reference estimates;
  by id seq;
  match=(col ne ans);
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Jul 2016 12:09:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-value-of-one-row-in-one-dataset-exists-in-one-row-of/m-p/286088#M58611</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-07-21T12:09:47Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if value of one row in one dataset exists in one row of other dataset by ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-value-of-one-row-in-one-dataset-exists-in-one-row-of/m-p/286123#M58630</link>
      <description>&lt;P&gt;OK, very similar to your own answer but this will assign both 0's and 1's:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;merge estimates reference;&lt;/P&gt;
&lt;P&gt;by id;&lt;/P&gt;
&lt;P&gt;array ans {4};&lt;/P&gt;
&lt;P&gt;array col {4};&lt;/P&gt;
&lt;P&gt;array match {4};&lt;/P&gt;
&lt;P&gt;do _n_=1 to 4;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;match{_n_} = (whichn(ans{_n_}, of col{*}) = 0);&amp;nbsp;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2016 13:40:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-value-of-one-row-in-one-dataset-exists-in-one-row-of/m-p/286123#M58630</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-07-21T13:40:15Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if value of one row in one dataset exists in one row of other dataset by ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-value-of-one-row-in-one-dataset-exists-in-one-row-of/m-p/286309#M58696</link>
      <description>&lt;PRE&gt;
It is IML thing .


data reference;
input id $ col1 col2 col3 col4;
datalines;
A1 5 15 20 40
A2 11 12 13 37
A3 38 39 40 42
A4 5 25 35 41 
;

data estimates;
input id $ ans1 ans2 ans3 ans4;
datalines;
A1 8 15 40 30
A2 9 10 11 46
A3 38 39 40 42
A4 5 25 35 41 
;
proc iml;
use reference;
read all var _num_ into x[r=id];
close;
use estimates;
read all var _num_ into y;
close;
z=(x^=y);
create want from z[r=id c=('match1':'match'+char(ncol(x)))];
append from z[r=id];
close;
quit;
&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Jul 2016 02:08:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-value-of-one-row-in-one-dataset-exists-in-one-row-of/m-p/286309#M58696</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-07-22T02:08:34Z</dc:date>
    </item>
  </channel>
</rss>

