<?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 Merge two datasets to delete a new variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merge-two-datasets-to-delete-a-new-variable/m-p/761633#M241035</link>
    <description>&lt;P&gt;Dear community,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;I am trying to delete a companyid (compid) if one of the employee last and first name matches with another employee last and first name in two different dataset. Of course, these are sample datasets. Even if an employee first and last name matches in both datasets then I want to delete that company id (compid field), there are hundreds of employees in real data. I have sample code which I tried and I am getting error. Please give me any suggestions.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* sample dataset1 birthday*/
data birthday;
   input compid birthdat date7.
         lastname $18.
         firstnam $15.
         phone $4.;
		 format birthdat mmddyy10.;
         datalines;
459287 05JAN39 RODRIGUES        JUAN           5879
127845 25DEC48 MEDER            VLADIMIR       6231
254896 06APR54 TAYLOR-HUNYADI   ITO            0231
;
run;

/*Sample dataset2 tempbirthday*/
proc sql;
create table WORK.TEMPBIRTHDAY( bufsize=65536 )
  (
   compid num,
   birthdat num format=MMDDYY10.,
   lastname char(18),
   firstnam char(15),
   phone char(4)
  );
insert into WORK.TEMPBIRTHDAY
      values(459287,'04MAY98'd, 'NISHIMATSU-LYNCH','RICHARD', '6778')
      values(765112,'04MAY98'd, 'SMITH','ROBERT', '')
      values(219776,'15APR98'd, 'PASTORELLI','ZORA','')
      values(245233,'10APR98'd, 'ALI','SADIQ','')
      values(245234,'10APR98'd, 'MEHAILESCU','NADIA','')
      values(326721,'01MAY98'd, 'CALHOUN','WILLIS','')
	  values(459287,'05JAN39'd, 'RODRIGUES', 'JUAN', '5879')
	  values(127845,'25DEC48'd, 'MEDER', 'VLADIMIR', '6231')
	  values(254896,'06APR54'd, 'TAYLOR-HUNYADI', 'ITO', '0231')
;

quit;

/*sort both datasets by compid */
proc sort data=birthday ;
	by compid;
proc sort data=tempbirthday (rename=( birthdat=birthdat1 lastname=lastname1 firstnam=firstnam1 phone=phone1));
	by compid;
run;

/* delete the employees who is from same compid (companyid) */
data total1;
	merge birthday (in=ina) tempbirthday(in=inb);
	by compid;
	if ina and inb then do;
	delete compid;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks in advance&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 15 Aug 2021 02:59:28 GMT</pubDate>
    <dc:creator>buddha_d</dc:creator>
    <dc:date>2021-08-15T02:59:28Z</dc:date>
    <item>
      <title>Merge two datasets to delete a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-two-datasets-to-delete-a-new-variable/m-p/761633#M241035</link>
      <description>&lt;P&gt;Dear community,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;I am trying to delete a companyid (compid) if one of the employee last and first name matches with another employee last and first name in two different dataset. Of course, these are sample datasets. Even if an employee first and last name matches in both datasets then I want to delete that company id (compid field), there are hundreds of employees in real data. I have sample code which I tried and I am getting error. Please give me any suggestions.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* sample dataset1 birthday*/
data birthday;
   input compid birthdat date7.
         lastname $18.
         firstnam $15.
         phone $4.;
		 format birthdat mmddyy10.;
         datalines;
459287 05JAN39 RODRIGUES        JUAN           5879
127845 25DEC48 MEDER            VLADIMIR       6231
254896 06APR54 TAYLOR-HUNYADI   ITO            0231
;
run;

/*Sample dataset2 tempbirthday*/
proc sql;
create table WORK.TEMPBIRTHDAY( bufsize=65536 )
  (
   compid num,
   birthdat num format=MMDDYY10.,
   lastname char(18),
   firstnam char(15),
   phone char(4)
  );
insert into WORK.TEMPBIRTHDAY
      values(459287,'04MAY98'd, 'NISHIMATSU-LYNCH','RICHARD', '6778')
      values(765112,'04MAY98'd, 'SMITH','ROBERT', '')
      values(219776,'15APR98'd, 'PASTORELLI','ZORA','')
      values(245233,'10APR98'd, 'ALI','SADIQ','')
      values(245234,'10APR98'd, 'MEHAILESCU','NADIA','')
      values(326721,'01MAY98'd, 'CALHOUN','WILLIS','')
	  values(459287,'05JAN39'd, 'RODRIGUES', 'JUAN', '5879')
	  values(127845,'25DEC48'd, 'MEDER', 'VLADIMIR', '6231')
	  values(254896,'06APR54'd, 'TAYLOR-HUNYADI', 'ITO', '0231')
;

quit;

/*sort both datasets by compid */
proc sort data=birthday ;
	by compid;
proc sort data=tempbirthday (rename=( birthdat=birthdat1 lastname=lastname1 firstnam=firstnam1 phone=phone1));
	by compid;
run;

/* delete the employees who is from same compid (companyid) */
data total1;
	merge birthday (in=ina) tempbirthday(in=inb);
	by compid;
	if ina and inb then do;
	delete compid;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks in advance&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 15 Aug 2021 02:59:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-two-datasets-to-delete-a-new-variable/m-p/761633#M241035</guid>
      <dc:creator>buddha_d</dc:creator>
      <dc:date>2021-08-15T02:59:28Z</dc:date>
    </item>
    <item>
      <title>Re: Merge two datasets to delete a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-two-datasets-to-delete-a-new-variable/m-p/761641#M241037</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/139130"&gt;@buddha_d&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The DELETE statement deletes a row of data not just a single variable. If this is what you want then just remove the variable name from the delete statement and your code will work.&lt;/P&gt;
&lt;P&gt;You can't delete a variable (the column) from a specific row (observation). You can set the variable in a specific row ("the cell") to missing or change it but not delete a "cell". SAS tables are rectangular.&lt;/P&gt;</description>
      <pubDate>Sun, 15 Aug 2021 03:23:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-two-datasets-to-delete-a-new-variable/m-p/761641#M241037</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-08-15T03:23:01Z</dc:date>
    </item>
    <item>
      <title>Re: Merge two datasets to delete a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-two-datasets-to-delete-a-new-variable/m-p/761644#M241039</link>
      <description>&lt;P&gt;Yes I agree Patrick. In the sample data case, I want to remove company id (compid) '459287' as it meets the criteria of present in both datasets. Rest of the data after merging, could be the same. The output dataset should look like this&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="buddha_d_0-1629000386173.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/62594i6107D72E9C79E9EE/image-size/large?v=v2&amp;amp;px=999" role="button" title="buddha_d_0-1629000386173.png" alt="buddha_d_0-1629000386173.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 15 Aug 2021 04:06:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-two-datasets-to-delete-a-new-variable/m-p/761644#M241039</guid>
      <dc:creator>buddha_d</dc:creator>
      <dc:date>2021-08-15T04:06:53Z</dc:date>
    </item>
    <item>
      <title>Re: Merge two datasets to delete a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-two-datasets-to-delete-a-new-variable/m-p/761645#M241040</link>
      <description>&lt;P&gt;Given the required logic you describe not sure why compid 127845 would remain in your desired result.&lt;/P&gt;
&lt;P&gt;Below the code for the logic as I understand it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data total1;
  merge 
    birthday (in=ina)
    tempbirthday(in=inb);
  by compid;
  if ina and inb and lastname=lastname1 and firstnam=firstnam1 then delete;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 15 Aug 2021 04:30:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-two-datasets-to-delete-a-new-variable/m-p/761645#M241040</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-08-15T04:30:18Z</dc:date>
    </item>
    <item>
      <title>Re: Merge two datasets to delete a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-two-datasets-to-delete-a-new-variable/m-p/761647#M241041</link>
      <description>&lt;P&gt;Patrick, you are correct. Compid 127845 shouldn't be there in the dataset. In fact, all the compids&amp;nbsp;459287, 127845, 254896 shouldn't be seen in the output dataset as there is at least one matching observation (compid on both datasets). The highlighted record should be deleted as well (though the first and last names are different, I don't want to see if the two different employees work for the same company)&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="buddha_d_0-1629003334734.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/62595iD779A32FF7C85528/image-size/large?v=v2&amp;amp;px=999" role="button" title="buddha_d_0-1629003334734.png" alt="buddha_d_0-1629003334734.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;which will be accomplished by using this code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/* delete the employees who is from same compid */&lt;BR /&gt;data total1;&lt;BR /&gt;merge&lt;BR /&gt;birthday (in=ina)&lt;BR /&gt;tempbirthday(in=inb);&lt;BR /&gt;by compid;&lt;BR /&gt;if not ina and inb ;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Sun, 15 Aug 2021 04:58:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-two-datasets-to-delete-a-new-variable/m-p/761647#M241041</guid>
      <dc:creator>buddha_d</dc:creator>
      <dc:date>2021-08-15T04:58:51Z</dc:date>
    </item>
    <item>
      <title>Re: Merge two datasets to delete a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-two-datasets-to-delete-a-new-variable/m-p/761683#M241052</link>
      <description>&lt;P&gt;(NOT INA AND INB) is different than NOT (INA and INB).&lt;/P&gt;
&lt;P&gt;This first just finds the observations that exist in B that are not in A.&lt;/P&gt;
&lt;P&gt;The second also includes the cases that exist in A that are not in B.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 15 Aug 2021 15:35:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-two-datasets-to-delete-a-new-variable/m-p/761683#M241052</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-15T15:35:56Z</dc:date>
    </item>
  </channel>
</rss>

