BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
aminkarimid
Lapis Lazuli | Level 10

Hello everybody,

I have two tables which are shown below:

 

Table 01
DateTimeNamePrice
11asd1
12asd2
12sdf1
14sdf2
21dfg1
22sdf2
31asd3
32fgh1
33fgh2

 

Table 02
NameStatus
sdf1
zxc2
xcv1
cvb1
fgh2

 

 

Now, I want to find duplicate data by Name based on table 02, and then delete them. I mean that the SAS searchs tables to find data with same name and delete them just from table 01, like the table below:

 

Final table
DateTimeNamePrice
11asd1
12asd2
21dfg1
31asd3

 

 

All variable except Name are numeric.

 

1. How can I do that?

2. How can I report on deleted data?

 

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
WesleyD
SAS Employee

You could use proc sql:

 

proc sql;
	create table table01 as
	select * from table01
	where name not in (select name from table02);
quit;

 If you'd like to report on what rows would be deleted, you could just run the inversed query beforehand:

 

 

proc sql;
	create table table01 as
	select * from table01
	where name in (select name from table02);
quit;

 

 

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

Do a join on name:

proc sort data=have1;
by name;
run;

proc sort data=have2;
by name;
run;

data
  want
  deleted
;
merge
  have1 (in=a)
  have2 (in=b keep=name);
;
by name;
if a;
if b
then output deleted;
else output want;
run;

Or (if the size of data allows) create a format from have2 that renders a 1 for each existing name, and 0 otherwise. Then you can avoid sorting of have1.

WesleyD
SAS Employee

You could use proc sql:

 

proc sql;
	create table table01 as
	select * from table01
	where name not in (select name from table02);
quit;

 If you'd like to report on what rows would be deleted, you could just run the inversed query beforehand:

 

 

proc sql;
	create table table01 as
	select * from table01
	where name in (select name from table02);
quit;

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1786 views
  • 0 likes
  • 3 in conversation