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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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