<?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 ensure two datasets to contain  the same observations with the same date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-ensure-two-datasets-to-contain-the-same-observations-with/m-p/385495#M92221</link>
    <description>&lt;P&gt;If I understand you, is this what you are after, a comparison:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; WORK.TEST1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; infile datalines dsd truncover;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input CUSIP:$8. fe:&lt;STRONG&gt;32.&lt;/STRONG&gt; yymm_a:YYMMN6.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format yymm_a YYMMN6.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; label CUSIP="CUSIP/SEDOL" fe="Mean Estimate";&lt;/P&gt;&lt;P&gt;datalines4;&lt;/P&gt;&lt;P&gt;00036020,0.06,199201&lt;/P&gt;&lt;P&gt;00036020,0.06,199201&lt;/P&gt;&lt;P&gt;00036020,0.06,199201&lt;/P&gt;&lt;P&gt;00036020,0.07,199201&lt;/P&gt;&lt;P&gt;00036110,0.91,199705&lt;/P&gt;&lt;P&gt;00036110,1.24,199705&lt;/P&gt;&lt;P&gt;00036110,1.47,199705&lt;/P&gt;&lt;P&gt;00036110,1.73,199705&lt;/P&gt;&lt;P&gt;00036110,1.55,199705&lt;/P&gt;&lt;P&gt;00036110,1.61,199705&lt;/P&gt;&lt;P&gt;00036110,1.54,199705&lt;/P&gt;&lt;P&gt;00036110,1.25,199705&lt;/P&gt;&lt;P&gt;00036110,1.19,199705&lt;/P&gt;&lt;P&gt;00036110,1.65,199705&lt;/P&gt;&lt;P&gt;00036110,1.71,199705&lt;/P&gt;&lt;P&gt;00036110,1.24,199705&lt;/P&gt;&lt;P&gt;00036110,1.46,199705&lt;/P&gt;&lt;P&gt;00036110,1.47,199810&lt;/P&gt;&lt;P&gt;00036110,1.04,199810&lt;/P&gt;&lt;P&gt;00036110,1.73,199810&lt;/P&gt;&lt;P&gt;;;;;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; WORK.TEST2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; infile datalines dsd truncover;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input CUSIP:$8. fe:&lt;STRONG&gt;32.&lt;/STRONG&gt; yymm_a:YYMMN6.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format yymm_a YYMMN6.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; label CUSIP="CUSIP/SEDOL" fe="Mean Estimate";&lt;/P&gt;&lt;P&gt;datalines4;&lt;/P&gt;&lt;P&gt;00036020,0.09,199801&lt;/P&gt;&lt;P&gt;00036020,0.05,199801&lt;/P&gt;&lt;P&gt;00036020,0.03,199801&lt;/P&gt;&lt;P&gt;00036020,0.03,199801&lt;/P&gt;&lt;P&gt;00036020,0.07,199801&lt;/P&gt;&lt;P&gt;00036020,0.03,199801&lt;/P&gt;&lt;P&gt;00036020,0.06,199801&lt;/P&gt;&lt;P&gt;00036020,0.03,199801&lt;/P&gt;&lt;P&gt;00036020,0.04,199801&lt;/P&gt;&lt;P&gt;00036110,0.88,199705&lt;/P&gt;&lt;P&gt;00036110,0.46,199705&lt;/P&gt;&lt;P&gt;00036110,0.57,199705&lt;/P&gt;&lt;P&gt;00036110,0.47,199705&lt;/P&gt;&lt;P&gt;00036110,0.91,199705&lt;/P&gt;&lt;P&gt;00036110,0.93,199705&lt;/P&gt;&lt;P&gt;00036110,0.41,199705&lt;/P&gt;&lt;P&gt;00036110,0.65,199705&lt;/P&gt;&lt;P&gt;00036110,0.51,199705&lt;/P&gt;&lt;P&gt;00036110,0.47,199705&lt;/P&gt;&lt;P&gt;00036110,0.88,199810&lt;/P&gt;&lt;P&gt;;;;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sort data=test1 nodupkey;&lt;BR /&gt;by cusip yymm_a;&lt;BR /&gt;run;&lt;BR /&gt;proc sort data=test2 nodupkey;&lt;BR /&gt;by cusip yymm_a;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data exist_only_test1 exist_only_test2 exist_test1_test2 ;&lt;BR /&gt;merge test1(in=a) test2(in=b );&lt;BR /&gt;by cusip yymm_a;&lt;BR /&gt;if a and b then output exist_test1_test2;&lt;BR /&gt;else if a and not b then output exist_only_test1;&lt;BR /&gt;else if b and not a then output exist_only_test2;&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Thu, 03 Aug 2017 21:19:44 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2017-08-03T21:19:44Z</dc:date>
    <item>
      <title>How to ensure two datasets to contain  the same observations with the same date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-ensure-two-datasets-to-contain-the-same-observations-with/m-p/385486#M92220</link>
      <description>&lt;P&gt;Hi, My datasets like this. I wanna make sure that both datasets contains the same cusips with the same yymm_a. Thanks&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.TEST2;
  infile datalines dsd truncover;
  input CUSIP:$8. fe:32. yymm_a:YYMMN6.;
  format yymm_a YYMMN6.;
  label CUSIP="CUSIP/SEDOL" fe="Mean Estimate";
datalines4;
00036020,0.06,199201
00036020,0.06,199201
00036020,0.06,199201
00036020,0.07,199201
00036110,0.91,199705
00036110,1.24,199705
00036110,1.47,199705
00036110,1.73,199705
00036110,1.55,199705
00036110,1.61,199705
00036110,1.54,199705
00036110,1.25,199705
00036110,1.19,199705
00036110,1.65,199705
00036110,1.71,199705
00036110,1.24,199705
00036110,1.46,199705
00036110,1.47,199810
00036110,1.04,199810
00036110,1.73,199810
;;;;
data WORK.TEST1;
  infile datalines dsd truncover;
  input CUSIP:$8. fe:32. yymm_a:YYMMN6.;
  format yymm_a YYMMN6.;
  label CUSIP="CUSIP/SEDOL" fe="Mean Estimate";
datalines4;
00036020,0.09,199801
00036020,0.05,199801
00036020,0.03,199801
00036020,0.03,199801
00036020,0.07,199801
00036020,0.03,199801
00036020,0.06,199801
00036020,0.03,199801
00036020,0.04,199801
00036110,0.88,199705
00036110,0.46,199705
00036110,0.57,199705
00036110,0.47,199705
00036110,0.91,199705
00036110,0.93,199705
00036110,0.41,199705
00036110,0.65,199705
00036110,0.51,199705
00036110,0.47,199705
00036110,0.88,199810
;;;;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The code I tried which worked &amp;nbsp;well when the amount of samples is not very large.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test11;
set test1;
run; 
data test21;
set test2;
run;
proc sort data=test11 nodupkey;
by cusip yymm_a;
run;
proc sort data=test21 nodupkey;
by cusip yymm_e;
run;
proc sql;
create table wtest as select  a.cusip,b.cusip as cusip1,a.yymm_a,b.yymm_e
from test11  as a,
	 test21  as b
where a.cusip=b.cusip and 
	  a.yymm_a=b.yymm_a;
quit;
proc sql;
create table test13 as select *
from test1
where cusip in (select cusip from wtest) and 
	  yymm_a in (select yymm_a from wtest);
quit;
proc sql;
create table test23 as select *
from test2
where cusip in (select cusip from wtest) and 
	  yymm_e in (select yymm_e from wtest);
quit; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2017 20:45:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-ensure-two-datasets-to-contain-the-same-observations-with/m-p/385486#M92220</guid>
      <dc:creator>lixuan</dc:creator>
      <dc:date>2017-08-03T20:45:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to ensure two datasets to contain  the same observations with the same date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-ensure-two-datasets-to-contain-the-same-observations-with/m-p/385495#M92221</link>
      <description>&lt;P&gt;If I understand you, is this what you are after, a comparison:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; WORK.TEST1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; infile datalines dsd truncover;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input CUSIP:$8. fe:&lt;STRONG&gt;32.&lt;/STRONG&gt; yymm_a:YYMMN6.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format yymm_a YYMMN6.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; label CUSIP="CUSIP/SEDOL" fe="Mean Estimate";&lt;/P&gt;&lt;P&gt;datalines4;&lt;/P&gt;&lt;P&gt;00036020,0.06,199201&lt;/P&gt;&lt;P&gt;00036020,0.06,199201&lt;/P&gt;&lt;P&gt;00036020,0.06,199201&lt;/P&gt;&lt;P&gt;00036020,0.07,199201&lt;/P&gt;&lt;P&gt;00036110,0.91,199705&lt;/P&gt;&lt;P&gt;00036110,1.24,199705&lt;/P&gt;&lt;P&gt;00036110,1.47,199705&lt;/P&gt;&lt;P&gt;00036110,1.73,199705&lt;/P&gt;&lt;P&gt;00036110,1.55,199705&lt;/P&gt;&lt;P&gt;00036110,1.61,199705&lt;/P&gt;&lt;P&gt;00036110,1.54,199705&lt;/P&gt;&lt;P&gt;00036110,1.25,199705&lt;/P&gt;&lt;P&gt;00036110,1.19,199705&lt;/P&gt;&lt;P&gt;00036110,1.65,199705&lt;/P&gt;&lt;P&gt;00036110,1.71,199705&lt;/P&gt;&lt;P&gt;00036110,1.24,199705&lt;/P&gt;&lt;P&gt;00036110,1.46,199705&lt;/P&gt;&lt;P&gt;00036110,1.47,199810&lt;/P&gt;&lt;P&gt;00036110,1.04,199810&lt;/P&gt;&lt;P&gt;00036110,1.73,199810&lt;/P&gt;&lt;P&gt;;;;;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; WORK.TEST2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; infile datalines dsd truncover;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input CUSIP:$8. fe:&lt;STRONG&gt;32.&lt;/STRONG&gt; yymm_a:YYMMN6.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format yymm_a YYMMN6.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; label CUSIP="CUSIP/SEDOL" fe="Mean Estimate";&lt;/P&gt;&lt;P&gt;datalines4;&lt;/P&gt;&lt;P&gt;00036020,0.09,199801&lt;/P&gt;&lt;P&gt;00036020,0.05,199801&lt;/P&gt;&lt;P&gt;00036020,0.03,199801&lt;/P&gt;&lt;P&gt;00036020,0.03,199801&lt;/P&gt;&lt;P&gt;00036020,0.07,199801&lt;/P&gt;&lt;P&gt;00036020,0.03,199801&lt;/P&gt;&lt;P&gt;00036020,0.06,199801&lt;/P&gt;&lt;P&gt;00036020,0.03,199801&lt;/P&gt;&lt;P&gt;00036020,0.04,199801&lt;/P&gt;&lt;P&gt;00036110,0.88,199705&lt;/P&gt;&lt;P&gt;00036110,0.46,199705&lt;/P&gt;&lt;P&gt;00036110,0.57,199705&lt;/P&gt;&lt;P&gt;00036110,0.47,199705&lt;/P&gt;&lt;P&gt;00036110,0.91,199705&lt;/P&gt;&lt;P&gt;00036110,0.93,199705&lt;/P&gt;&lt;P&gt;00036110,0.41,199705&lt;/P&gt;&lt;P&gt;00036110,0.65,199705&lt;/P&gt;&lt;P&gt;00036110,0.51,199705&lt;/P&gt;&lt;P&gt;00036110,0.47,199705&lt;/P&gt;&lt;P&gt;00036110,0.88,199810&lt;/P&gt;&lt;P&gt;;;;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sort data=test1 nodupkey;&lt;BR /&gt;by cusip yymm_a;&lt;BR /&gt;run;&lt;BR /&gt;proc sort data=test2 nodupkey;&lt;BR /&gt;by cusip yymm_a;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data exist_only_test1 exist_only_test2 exist_test1_test2 ;&lt;BR /&gt;merge test1(in=a) test2(in=b );&lt;BR /&gt;by cusip yymm_a;&lt;BR /&gt;if a and b then output exist_test1_test2;&lt;BR /&gt;else if a and not b then output exist_only_test1;&lt;BR /&gt;else if b and not a then output exist_only_test2;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2017 21:19:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-ensure-two-datasets-to-contain-the-same-observations-with/m-p/385495#M92221</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-08-03T21:19:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to ensure two datasets to contain  the same observations with the same date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-ensure-two-datasets-to-contain-the-same-observations-with/m-p/385496#M92222</link>
      <description>&lt;P&gt;The simplest way is to run two proc sorts and a merge:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=test1 (keep=cusip yymm_a) out=need1&amp;nbsp;nodupkey;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; by cusip yymm_a;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=test2 (keep=cusip yymm_a) out=need2 nodupkey;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; by cusip yymm_a;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data test1_only test2_only both;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; merge need1 (in=in1) need2 (in=in2);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; by cusip yymm_a;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if in1=in2 then output both;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; else if in1 then output test1_only;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; else output test2_only;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2017 21:17:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-ensure-two-datasets-to-contain-the-same-observations-with/m-p/385496#M92222</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-08-03T21:17:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to ensure two datasets to contain  the same observations with the same date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-ensure-two-datasets-to-contain-the-same-observations-with/m-p/385548#M92242</link>
      <description>&lt;P&gt;Thank you ,your method is right, and my problem is how I can convert the result into my original datasets test1 and test2?&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2017 02:21:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-ensure-two-datasets-to-contain-the-same-observations-with/m-p/385548#M92242</guid>
      <dc:creator>lixuan</dc:creator>
      <dc:date>2017-08-04T02:21:31Z</dc:date>
    </item>
    <item>
      <title>How to make two datasets contain the same observations with same date.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-ensure-two-datasets-to-contain-the-same-observations-with/m-p/385630#M92274</link>
      <description>&lt;P&gt;Hi, I posted the problem yesterday and got no answer. My datasets like this. I wanna make sure that both datasets contains the same cusips with the same yymm_a without adding observations. Thanks ahead&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; WORK&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;TEST2&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token statement"&gt;infile&lt;/SPAN&gt; datalines dsd truncover&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt; CUSIP:&lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;8&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt; fe:&lt;SPAN class="token number"&gt;32&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt; yymm_a:YYMMN6&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token procnames"&gt;format&lt;/SPAN&gt; yymm_a YYMMN6&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token function"&gt;label&lt;/SPAN&gt; CUSIP&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"CUSIP/SEDOL"&lt;/SPAN&gt; fe&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"Mean Estimate"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token keyword"&gt;datalines&lt;/SPAN&gt;&lt;SPAN class="token data string"&gt;4&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token data string"&gt;00036020,0.06,199201
00036020,0.06,199201
00036020,0.06,199201
00036020,0.07,199201
00036110,0.91,199705
00036110,1.24,199705
00036110,1.47,199705
00036110,1.73,199705
00036110,1.55,199705
00036110,1.61,199705
00036110,1.54,199705
00036110,1.25,199705
00036110,1.19,199705
00036110,1.65,199705
00036110,1.71,199705
00036110,1.24,199705
00036110,1.46,199705
00036110,1.47,199810
00036110,1.04,199810
00036110,1.73,199810&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; WORK&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;TEST1&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token statement"&gt;infile&lt;/SPAN&gt; datalines dsd truncover&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt; CUSIP:&lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;8&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt; fe:&lt;SPAN class="token number"&gt;32&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt; yymm_a:YYMMN6&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token procnames"&gt;format&lt;/SPAN&gt; yymm_a YYMMN6&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token function"&gt;label&lt;/SPAN&gt; CUSIP&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"CUSIP/SEDOL"&lt;/SPAN&gt; fe&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"Mean Estimate"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token keyword"&gt;datalines&lt;/SPAN&gt;&lt;SPAN class="token data string"&gt;4&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token data string"&gt;00036020,0.09,199801
00036020,0.05,199801
00036020,0.03,199801
00036020,0.03,199801
00036020,0.07,199801
00036020,0.03,199801
00036020,0.06,199801
00036020,0.03,199801
00036020,0.04,199801
00036110,0.88,199705
00036110,0.46,199705
00036110,0.57,199705
00036110,0.47,199705
00036110,0.91,199705
00036110,0.93,199705
00036110,0.41,199705
00036110,0.65,199705
00036110,0.51,199705
00036110,0.47,199705
00036110,0.88,199810&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The codes I tried worked &amp;nbsp;well when the amount of samples is not very large, but with the number of observations increasing, the diffrerence happened.&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; test11&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; test1&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; 
&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; test21&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; test2&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;sort&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;test11 nodupkey&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token statement"&gt;by&lt;/SPAN&gt; cusip yymm_a&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;sort&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;test21 nodupkey&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token statement"&gt;by&lt;/SPAN&gt; cusip yymm_e&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;sql&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
create &lt;SPAN class="token statement"&gt;table&lt;/SPAN&gt; wtest as &lt;SPAN class="token statement"&gt;select&lt;/SPAN&gt;  a&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;cusip&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;b&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;cusip as cusip1&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;a&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;yymm_a&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;b&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;yymm_e
&lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt; test11  as a&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;
	 test21  as b
&lt;SPAN class="token statement"&gt;where&lt;/SPAN&gt; a&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;cusip&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;b&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;cusip and 
	  a&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;yymm_a&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;b&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;yymm_a&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;quit&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;sql&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
create &lt;SPAN class="token statement"&gt;table&lt;/SPAN&gt; test13 as &lt;SPAN class="token statement"&gt;select&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt; test1
&lt;SPAN class="token statement"&gt;where&lt;/SPAN&gt; cusip &lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token statement"&gt;select&lt;/SPAN&gt; cusip &lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt; wtest&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; and 
	  yymm_a &lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token statement"&gt;select&lt;/SPAN&gt; yymm_a &lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt; wtest&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;quit&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;sql&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
create &lt;SPAN class="token statement"&gt;table&lt;/SPAN&gt; test23 as &lt;SPAN class="token statement"&gt;select&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt; test2
&lt;SPAN class="token statement"&gt;where&lt;/SPAN&gt; cusip &lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token statement"&gt;select&lt;/SPAN&gt; cusip &lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt; wtest&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; and 
	  yymm_e &lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token statement"&gt;select&lt;/SPAN&gt; yymm_e &lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt; wtest&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;quit&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2017 12:08:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-ensure-two-datasets-to-contain-the-same-observations-with/m-p/385630#M92274</guid>
      <dc:creator>lixuan</dc:creator>
      <dc:date>2017-08-04T12:08:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to make two datasets contain the same observations with same date.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-ensure-two-datasets-to-contain-the-same-observations-with/m-p/385632#M92275</link>
      <description>&lt;P&gt;Ok, scrub the below, I ahve just checked your other posts and this was already given to you, hence why its not a good idea to duplicate post. &amp;nbsp;Please explain you request clearly, as I got to exactly the same thing as another member from what you posted, and this doesn't seem to cover what you want, hence explain what you want. &amp;nbsp;I will merge this with your other post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you not do it with proc compare:&lt;/P&gt;
&lt;PRE&gt;proc compare base=test2 (kee=cusip yymm_a) comp=test1 (keep=cuspid yymm_a) listall;
run;&lt;/PRE&gt;
&lt;P&gt;Or a simple sort merge:&lt;/P&gt;
&lt;PRE&gt;proc sort data=test2 out=b (keep=cusip yymm_a) nodupkey;
  by cusip yymm_a;
run;
proc sort data=test1 out=c (keep=cusip yymm_a) nodupkey;
  by cusip yymm_a;
run;
data want;
  merge b (in=a) c (in=b);
  by cusip yymm_a;
  if not(a and b);
run;

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2017 12:17:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-ensure-two-datasets-to-contain-the-same-observations-with/m-p/385632#M92275</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-08-04T12:17:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to make two datasets contain the same observations with same date.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-ensure-two-datasets-to-contain-the-same-observations-with/m-p/385634#M92276</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;Thanks ,sorry I didnt expaln my logic very clearly. I want the &amp;nbsp;both datasets to be sperately so I can compare the change of variable g. As the result , the same cusip with same date is wanted.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2017 12:37:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-ensure-two-datasets-to-contain-the-same-observations-with/m-p/385634#M92276</guid>
      <dc:creator>lixuan</dc:creator>
      <dc:date>2017-08-04T12:37:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to make two datasets contain the same observations with same date.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-ensure-two-datasets-to-contain-the-same-observations-with/m-p/385635#M92277</link>
      <description>&lt;P&gt;Maybe show what the output should be from the given test data. &amp;nbsp;Another guess, remove the not() function?&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2017 12:54:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-ensure-two-datasets-to-contain-the-same-observations-with/m-p/385635#M92277</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-08-04T12:54:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to make two datasets contain the same observations with same date.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-ensure-two-datasets-to-contain-the-same-observations-with/m-p/385682#M92289</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;I want the result is: As you can see , both table are seperated and cusip and yymm_a are same. I tried to merge your result with test1 and test2, but there are too many duplicated observations which I can't control in my result .&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;result of test1
cusip      g  yymm_a
00036110,0.91,199705
00036110,1.24,199705
00036110,1.47,199705
00036110,1.73,199705
00036110,1.55,199705
00036110,1.61,199705
00036110,1.54,199705
00036110,1.25,199705
00036110,1.19,199705
00036110,1.65,199705
00036110,1.71,199705
00036110,1.24,199705
00036110,1.46,199705
00036110,1.47,199810
00036110,1.04,199810
00036110,1.73,199810
result of test2
00036110,0.88,199705
00036110,0.46,199705
00036110,0.57,199705
00036110,0.47,199705
00036110,0.91,199705
00036110,0.93,199705
00036110,0.41,199705
00036110,0.65,199705
00036110,0.51,199705
00036110,0.47,199705
00036110,0.88,199810&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2017 15:24:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-ensure-two-datasets-to-contain-the-same-observations-with/m-p/385682#M92289</guid>
      <dc:creator>lixuan</dc:creator>
      <dc:date>2017-08-04T15:24:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to make two datasets contain the same observations with same date.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-ensure-two-datasets-to-contain-the-same-observations-with/m-p/385697#M92295</link>
      <description>&lt;P&gt;Yes, still not really following. &amp;nbsp;I am done for the day now, but got to here, maybe you can refine it with specific logic:&lt;/P&gt;
&lt;PRE&gt;data WORK.TEST2;
  infile datalines dsd truncover;
  input CUSIP:$8. fe:32. yymm_a:YYMMN6.;
  format yymm_a YYMMN6.;
  label CUSIP="CUSIP/SEDOL" fe="Mean Estimate";
datalines;
00036020,0.06,199201
00036020,0.06,199201
00036020,0.06,199201
00036020,0.07,199201
00036110,0.91,199705
00036110,1.24,199705
00036110,1.47,199705
00036110,1.73,199705
00036110,1.55,199705
00036110,1.61,199705
00036110,1.54,199705
00036110,1.25,199705
00036110,1.19,199705
00036110,1.65,199705
00036110,1.71,199705
00036110,1.24,199705
00036110,1.46,199705
00036110,1.47,199810
00036110,1.04,199810
00036110,1.73,199810
;
run;

data WORK.TEST1;
  infile datalines dsd truncover;
  input CUSIP:$8. fe:32. yymm_a:YYMMN6.;
  format yymm_a YYMMN6.;
  label CUSIP="CUSIP/SEDOL" fe="Mean Estimate";
datalines;
00036020,0.09,199801
00036020,0.05,199801
00036020,0.03,199801
00036020,0.03,199801
00036020,0.07,199801
00036020,0.03,199801
00036020,0.06,199801
00036020,0.03,199801
00036020,0.04,199801
00036110,0.88,199705
00036110,0.46,199705
00036110,0.57,199705
00036110,0.47,199705
00036110,0.91,199705
00036110,0.93,199705
00036110,0.41,199705
00036110,0.65,199705
00036110,0.51,199705
00036110,0.47,199705
00036110,0.88,199810
;
run;

data res1 (keep=cusip fe yymm_a) res2 (keep=cusip fe_tmp yymm_tmp rename=(fe_tmp=fe yymm_tmp=yymm_a));
  merge test1 (in=a) test2 (in=b rename=(fe=fe_tmp yymm_a=yymm_tmp));
  by cusip;
  if a and b and yymm_a ne yymm_tmp then delete;
  if a then output res1;
  if b then output res2;
run;
  &lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Aug 2017 16:06:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-ensure-two-datasets-to-contain-the-same-observations-with/m-p/385697#M92295</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-08-04T16:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to make two datasets contain the same observations with same date.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-ensure-two-datasets-to-contain-the-same-observations-with/m-p/385722#M92309</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;I study your codes, and I try to explain as my understanding. First, you deleted the part of a.cusip=b.cusip&amp;amp; a.yymm_a ne b.yymm_a, then the left part includes a.cusip=b.cusip&amp;amp; a.yymm_a=b.yymm_a &amp;nbsp;and a.cusip ne b.cusip; Second, you pick the left part in a. and left part in b. I wonder how your result looks like. Could you explain to me ?&lt;/P&gt;&lt;P&gt;My logic is very simple. you see cusip 00036110 whose date is 199705 in test1, and the date of cusip 00036110 in test2 is also 199705, so all the cusip 00036110 &amp;nbsp;with date 199705 should be kept in test1 and test2.&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2017 17:14:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-ensure-two-datasets-to-contain-the-same-observations-with/m-p/385722#M92309</guid>
      <dc:creator>lixuan</dc:creator>
      <dc:date>2017-08-04T17:14:13Z</dc:date>
    </item>
  </channel>
</rss>

