<?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: SUBSTITUTE ELEMENTS OF ONE DATASET WITH ANOTHER DATASET BY MATCHING ID in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/SUBSTITUTE-ELEMENTS-OF-ONE-DATASET-WITH-ANOTHER-DATASET-BY/m-p/744695#M29319</link>
    <description>&lt;P&gt;Sounds like you just want to MERGE the datasets and only keep the observations that were already in the first one.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data t2005;
  input id_company injury;
datalines;
123 0
245 1
322 0
355 1
4 1
5 0
666 0
7 0
;

data t2006;
  input id_company injury;
datalines;
123 1
245 1
322 0
343 0
4 1
5 1
677 0
7 0
;

proc sort data=t2005 ;
  by id_company;
run;
proc sort data=t2006 ;
  by id_company;
run;
&lt;BR /&gt;data want ;
  merge t2005(in=in1) t2006(in=in2);
  by id_company;
  if in1;
run;

proc print;
run;
proc compare data=t2005 compare=want;
  id id_company;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;Obs    id_company    injury

 1           4          1
 2           5          1
 3           7          0
 4         123          1
 5         245          1
 6         322          0
 7         355          1
 8         666          0

The COMPARE Procedure
Comparison of WORK.T2005 with WORK.WANT
(Method=EXACT)

Data Set Summary

Dataset              Created          Modified  NVar    NObs

WORK.T2005  30MAY21:14:08:51  30MAY21:14:08:51     2       8
WORK.WANT   30MAY21:14:08:51  30MAY21:14:08:51     2       8


Variables Summary

Number of Variables in Common: 2.
Number of ID Variables: 1.


Observation Summary

Observation      Base  Compare  ID

First Obs           1        1  id_company=4
First Unequal       2        2  id_company=5
Last  Unequal       4        4  id_company=123
Last  Obs           8        8  id_company=666

Number of Observations in Common: 8.
Total Number of Observations Read from WORK.T2005: 8.
Total Number of Observations Read from WORK.WANT: 8.

Number of Observations with Some Compared Variables Unequal: 2.
Number of Observations with All Compared Variables Equal: 6.


Values Comparison Summary

Number of Variables Compared with All Observations Equal: 0.
Number of Variables Compared with Some Observations Unequal: 1.
Total Number of Values which Compare Unequal: 2.
Maximum Difference: 1.


All Variables Compared have Unequal Values

Variable  Type  Len  Ndif   MaxDif

injury    NUM     8     2    1.000


The COMPARE Procedure
Comparison of WORK.T2005 with WORK.WANT
(Method=EXACT)

Value Comparison Results for Variables

____________________________________________________________
             ||       Base    Compare
 id_company  ||     injury     injury      Diff.     % Diff
 __________  ||  _________  _________  _________  _________
             ||
          5  ||          0     1.0000     1.0000          .
        123  ||          0     1.0000     1.0000          .
____________________________________________________________&lt;/PRE&gt;</description>
    <pubDate>Sun, 30 May 2021 18:09:53 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-05-30T18:09:53Z</dc:date>
    <item>
      <title>SUBSTITUTE ELEMENTS OF ONE DATASET WITH ANOTHER DATASET BY MATCHING ID</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SUBSTITUTE-ELEMENTS-OF-ONE-DATASET-WITH-ANOTHER-DATASET-BY/m-p/744678#M29317</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Given to dataset like below. I am trying to find a way to create a third dataset that is equal to dataset 2 but has&lt;/P&gt;&lt;P&gt;all the values of dataset 1 in injury when&amp;nbsp;id_company is the same.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would much appreciate any help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* Data set 1 */&lt;BR /&gt;data t2005;&lt;BR /&gt;input id_company injury;&lt;BR /&gt;datalines;&lt;BR /&gt;123 0&lt;BR /&gt;245 1&lt;BR /&gt;322 0&lt;BR /&gt;355 1&lt;BR /&gt;4 1&lt;BR /&gt;5 0&lt;BR /&gt;666 0&lt;BR /&gt;7 0&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/*Data set 2 */&lt;BR /&gt;data t2006;&lt;BR /&gt;input id_company injury;&lt;BR /&gt;datalines;&lt;BR /&gt;123 1&lt;BR /&gt;245 1&lt;BR /&gt;322 0&lt;BR /&gt;343 0&lt;BR /&gt;4 1&lt;BR /&gt;5 1&lt;BR /&gt;677 0&lt;BR /&gt;7 0&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Sun, 30 May 2021 15:41:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SUBSTITUTE-ELEMENTS-OF-ONE-DATASET-WITH-ANOTHER-DATASET-BY/m-p/744678#M29317</guid>
      <dc:creator>AB90</dc:creator>
      <dc:date>2021-05-30T15:41:45Z</dc:date>
    </item>
    <item>
      <title>Re: SUBSTITUTE ELEMENTS OF ONE DATASET WITH ANOTHER DATASET BY MATCHING ID</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SUBSTITUTE-ELEMENTS-OF-ONE-DATASET-WITH-ANOTHER-DATASET-BY/m-p/744691#M29318</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I think it's this what you want but please check thoroughly.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=t2005; by id_company; run;
proc sort data=t2006; by id_company; run;
data temp;
 update t2006 /* Put master-data-set first     */
        t2005 /* Then put transaction-data-set */
		;
 by id_company;
run;

PROC SQL noprint;
 create table dataset3 as
 select *
 from temp
 where id_company IN (select id_company from t2006)
 ;
 QUIT;
/* end-of-program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Sun, 30 May 2021 17:19:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SUBSTITUTE-ELEMENTS-OF-ONE-DATASET-WITH-ANOTHER-DATASET-BY/m-p/744691#M29318</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-05-30T17:19:56Z</dc:date>
    </item>
    <item>
      <title>Re: SUBSTITUTE ELEMENTS OF ONE DATASET WITH ANOTHER DATASET BY MATCHING ID</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SUBSTITUTE-ELEMENTS-OF-ONE-DATASET-WITH-ANOTHER-DATASET-BY/m-p/744695#M29319</link>
      <description>&lt;P&gt;Sounds like you just want to MERGE the datasets and only keep the observations that were already in the first one.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data t2005;
  input id_company injury;
datalines;
123 0
245 1
322 0
355 1
4 1
5 0
666 0
7 0
;

data t2006;
  input id_company injury;
datalines;
123 1
245 1
322 0
343 0
4 1
5 1
677 0
7 0
;

proc sort data=t2005 ;
  by id_company;
run;
proc sort data=t2006 ;
  by id_company;
run;
&lt;BR /&gt;data want ;
  merge t2005(in=in1) t2006(in=in2);
  by id_company;
  if in1;
run;

proc print;
run;
proc compare data=t2005 compare=want;
  id id_company;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;Obs    id_company    injury

 1           4          1
 2           5          1
 3           7          0
 4         123          1
 5         245          1
 6         322          0
 7         355          1
 8         666          0

The COMPARE Procedure
Comparison of WORK.T2005 with WORK.WANT
(Method=EXACT)

Data Set Summary

Dataset              Created          Modified  NVar    NObs

WORK.T2005  30MAY21:14:08:51  30MAY21:14:08:51     2       8
WORK.WANT   30MAY21:14:08:51  30MAY21:14:08:51     2       8


Variables Summary

Number of Variables in Common: 2.
Number of ID Variables: 1.


Observation Summary

Observation      Base  Compare  ID

First Obs           1        1  id_company=4
First Unequal       2        2  id_company=5
Last  Unequal       4        4  id_company=123
Last  Obs           8        8  id_company=666

Number of Observations in Common: 8.
Total Number of Observations Read from WORK.T2005: 8.
Total Number of Observations Read from WORK.WANT: 8.

Number of Observations with Some Compared Variables Unequal: 2.
Number of Observations with All Compared Variables Equal: 6.


Values Comparison Summary

Number of Variables Compared with All Observations Equal: 0.
Number of Variables Compared with Some Observations Unequal: 1.
Total Number of Values which Compare Unequal: 2.
Maximum Difference: 1.


All Variables Compared have Unequal Values

Variable  Type  Len  Ndif   MaxDif

injury    NUM     8     2    1.000


The COMPARE Procedure
Comparison of WORK.T2005 with WORK.WANT
(Method=EXACT)

Value Comparison Results for Variables

____________________________________________________________
             ||       Base    Compare
 id_company  ||     injury     injury      Diff.     % Diff
 __________  ||  _________  _________  _________  _________
             ||
          5  ||          0     1.0000     1.0000          .
        123  ||          0     1.0000     1.0000          .
____________________________________________________________&lt;/PRE&gt;</description>
      <pubDate>Sun, 30 May 2021 18:09:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SUBSTITUTE-ELEMENTS-OF-ONE-DATASET-WITH-ANOTHER-DATASET-BY/m-p/744695#M29319</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-05-30T18:09:53Z</dc:date>
    </item>
  </channel>
</rss>

