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]

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1341 views
  • 0 likes
  • 3 in conversation