DATA Step, Macro, Functions and more

update data

Reply
N/A
Posts: 0

update data

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
Super User
Posts: 5,257

Re: update data

It would be helpful to see you sql update code.

/Linus
Data never sleeps
N/A
Posts: 0

Re: update data

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
Respected Advisor
Posts: 3,777

Re: update data

[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]
N/A
Posts: 0

Re: update data

Great !!!
Thank you very much
Respected Advisor
Posts: 3,777

Re: update data

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]
Ask a Question
Discussion stats
  • 5 replies
  • 160 views
  • 0 likes
  • 3 in conversation