BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi all,

I'm trying to run a proc sql, deleting records where one variable = another variable but getting unexpected results. Basically I return many records where variable1 does indeed equal variable 2.

Here's my code;

proc sql;
create table combined3 as
select t1.PolicyNumber,
t1.AnnualPremium,
t2.AnnualPremium as AnnualPremium2
from brendan.aug as t1
left join
brendan.july as t2
on t1.PolicyNumber = t2.PolicyNumber
where t1.AnnualPremium = t2.AnnualPremium;
quit;

If anyone can tell me what I'm doing wrong I'd be most appreciative.

Many thanks in advamnce.
2 REPLIES 2
DBailey
Lapis Lazuli | Level 10
presuming you mean to create a table (combined3) that only has records where the annual premium for a policy is different between brendan.aug and brendan.july, then:

proc sql;
create table combined3 as
select t1.PolicyNumber,
t1.AnnualPremium,
t2.AnnualPremium as AnnualPremium2
from brendan.aug as t1
left join
brendan.july as t2
on t1.PolicyNumber = t2.PolicyNumber
where
t1.AnnualPremium ne coalesce(t2.AnnualPremium,0);
quit;
Ksharp
Super User
[pre]
data class;
set sashelp.class;
run;
data match;
sex='F';
run;
proc sql;
delete from class
where sex in (select sex from match);
quit;
[/pre]


Before doing this code,Recommend you to back up your origin dataset,
Because it will delete rows in the origin dataset.


Ksharp

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 728 views
  • 0 likes
  • 3 in conversation