Help using Base SAS procedures

getting only the non intersection records

Reply
Contributor
Posts: 57

getting only the non intersection records

Hi,

I have few data sets like DS1, DS2 and DS3 with "cid" as the only variable.

DS1 DS2 DS3

CID CID CID
100 100 101
101 102 106
102 105 107
103 108
104

In these Data sets there are some records which is present in more than one data set. I want the remove the intersecting records for the other data sets. My way is to use merge statement for each combination to remove the intersections, but it is so ugly and lot of data steps. Is there a smooth ways of dealing with such issues?

Thanks in advance.

Sandy.
N/A
Posts: 0

Re: getting only the non intersection records

If I understand right, you can try something like this:
proc sql;
delete from ds2
where cid in (select distinct cid from ds1);
quit;
Super Contributor
Super Contributor
Posts: 3,174

Re: getting only the non intersection records

Posted in reply to deleted_user
Sounds like you want to replace your original files (at some point) and eliminate the redundant observations (based on CID values).

Explore using PROC SORT NODUPKEY with DUPOUT and identify each incoming observation by file and observation_number. With the DUPOUT file, then you have a source to use to DELETE observations back in the original file with a MERGE/BY process.

Scott Barry
SBBWorks, Inc.
Super Contributor
Posts: 474

Re: getting only the non intersection records

If I got this right, a single merge with every datasets will suffice.

You just need to work a subsetting if that will suite your needs.

For example the following:
[pre]
data OUT;
merge DS1 (in=D1) DS2 (in=D2) DS3 (in=D3);
by CID;
if (D1 and D2 and D3) then delete;
run;
[/pre]
Or..
[pre]
data OUT;
merge DS1 (in=D1) DS2 (in=D2) DS3 (in=D3);
by CID;
if not (D1 and D2 and D3);
run;
[/pre]
both will do the same, and will exclude the observations that full match on the 3 tables (3 way intersection).

Bare in mind that one requisite for the merge to work, is that only one of the tables may hold duplicate key values.

Check this info:
http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a000761932.htm

Cheers from Portugal.

Daniel Santos @ www.cgd.pt
Contributor
Posts: 57

Re: getting only the non intersection records

Posted in reply to DanielSantos
Thank you for all your suggestions. It was very helpful. Also, got to know about dupout. Cool feature.

Sandy.
Ask a Question
Discussion stats
  • 4 replies
  • 152 views
  • 0 likes
  • 4 in conversation