BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hello,

I have the following data:

table data1:
conto descr imp attr
1234 asad__ 20 1
1234 asad__ 20 1
1236 asdasd 10 2
1238 asdafffd 30 3
1240 wewew 54 4

table data2
conto attr
1234 5
1236 6
1238 8
1240 9

I'd like to update the field "attr" in table "data1" from table "data2", without use proc Sql.
and using filed conto as key
The relation is n to 1
I can't do this with update instrucion (the result is :

conto descr imp attr
1234 asad__ 20 5
1234 asad__ 20 1
1236 asdasd 10 6
1238 asdafffd 30 8
1240 wewew 54 9
)
Thanks
5 REPLIES 5
LinusH
Tourmaline | Level 20
It would be helpful to see you sql update code.

/Linus
Data never sleeps
deleted_user
Not applicable
here you are my code;

data data1_mod;
modify data1 data2;
by conto;
run;


in data1 duplicated key, the first record only in updated

tks
data_null__
Jade | Level 19
[pre]
data _1;
input conto$ descr$ imp attr;
cards;
1234 asad__ 20 1
1234 asad__ 20 1
1235 asad__ 20 9
1235 asad__ 20 2
1236 asdasd 10 2
1238 asdafffd 30 3
1240 wewew 54 4
;;;;
run;
data _2(index=(conto));
input conto$ attr;
cards;
1234 5
1236 6
1238 8
1240 9
;;;;
run;
data _3;
set _1;
set _2 key=conto/unique;
if _error_ then _error_ = 0 /*maybe do something else */;
run;
proc print;
run;
[/pre]
deleted_user
Not applicable
Great !!!
Thank you very much
data_null__
Jade | Level 19
I see had been using modify. That works equally well with a keyed SET.

[pre]
data _1;
input conto$ descr$ imp attr;
cards;
1234 asad__ 20 1
1234 asad__ 20 1
1235 asad__ 20 9
1235 asad__ 20 2
1236 asdasd 10 2
1238 asdafffd 30 3
1240 wewew 54 4
;;;;
run;
data _2(index=(conto));
input conto$ attr;
cards;
1234 5
1236 6
1238 8
1240 9
;;;;
run;
data _1;
modify _1;
set _2 key=conto/unique;
if not _error_ then replace;
else _error_ = 0;
run;
proc print data=_1;
run;
[/pre]

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
  • 5 replies
  • 757 views
  • 0 likes
  • 3 in conversation