BookmarkSubscribeRSS Feed
Datino
Obsidian | Level 7

Hello,

 

I'm trying to update the names table, but only if two of its columns match the ones from the donations table. Is it possible to do it in a single block of code?

 

data names;
input name $ ssn $ invited $;
datalines;
john 10 n
phil 12 n
charles 13 n
;
data donations;
input name $ ssn $ donated;
datalines;
joe 23 1000
george 18 4599
phil 12 6553
;

proc sql;
	update names as a
	set invited='y'
	where (a.name=donations.name and a.ssn=donations.ssn);
quit;
2 REPLIES 2
Jagadishkatam
Amethyst | Level 16

Please try

 

proc sql;
create table test as select a.name,a.ssn,b.donated, 
case when a.name=b.name and a.ssn=b.ssn then 'y' else a._invited end as invited 
from names(rename=(invited=_invited)) as a left join donations as b on a.name=b.name and a.ssn=b.ssn;
quit;
Thanks,
Jag
Ksharp
Super User
data names;
input name $ ssn $ invited $;
datalines;
john 10 n
phil 12 n
charles 13 n
;
data donations;
input name $ ssn $ donated;
datalines;
joe 23 1000
george 18 4599
phil 12 6553
;

proc sql;
	update names as a
	set invited='y'
	where exists(select * from donations where 
a.nam
e=donations.name and a.ssn=donations.ssn);
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!

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
  • 738 views
  • 1 like
  • 3 in conversation