BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ger15xxhcker
Quartz | Level 8

Hi,

I have a table with ~200k rows and i have to update it from another table which has the same columns, but some columns has different values in it .How can i update the first table with the second? I have 2 ID -s in it.

 

Thanks for all.

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Use the update statement. That's exactly what it does.

 

data a;
input id1    id2     a $     b $    c $;
datalines;
   1     10   x1   x2   x3
   2     20   y1   y2   y3 
   3     30   z1   z2   z3
   4     40   r1   r2   r3
;
 
data b;
input id1    id2     a $     b $    c $;
datalines;
   1     10   x1   x2   x3
   2     20   y1   y2   y3 
   3     30   z4   z5   z3
;

data c;
update a b;
by id1 id2;
run;

proc print; run;
PG

View solution in original post

3 REPLIES 3
mkeintz
PROC Star

Please show a sample of the two datasets before and the single dataset after.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
ger15xxhcker
Quartz | Level 8

base table:

id1    id2     a     b    c

   1     10   x1   x2   x3

   2     20   y1   y2   y3 

   3     30   z1   z2   z3

   4     40   r1    r2   r3

 

i got this table from a source

id1    id2     a     b    c

   1     10   x1   x2   x3

   2     20   y1   y2   y3 

   3     30   z4   z5   z3

 

and i have to update the base table with the second one like this:

final:

id1    id2     a     b    c

   1     10   x1   x2   x3

   2     20   y1   y2   y3 

   3     30   z4   z5   z3

   4     40   r1    r2    r3

 

 

PGStats
Opal | Level 21

Use the update statement. That's exactly what it does.

 

data a;
input id1    id2     a $     b $    c $;
datalines;
   1     10   x1   x2   x3
   2     20   y1   y2   y3 
   3     30   z1   z2   z3
   4     40   r1   r2   r3
;
 
data b;
input id1    id2     a $     b $    c $;
datalines;
   1     10   x1   x2   x3
   2     20   y1   y2   y3 
   3     30   z4   z5   z3
;

data c;
update a b;
by id1 id2;
run;

proc print; run;
PG

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