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 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!

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