SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

How to replace a row from another table

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 15
Accepted Solution

How to replace a row from another table

Hi every one.

Now I have dataset A:

Date AZWMTG
1/1/2015203050
1/2/2015***
1/3/2015***
1/4/2015***
1/5/2015***
1/6/2015***
1/7/2015***
1/8/2015***

Now I have dataset B:

Date AZWMTG
1/1/201510012

I want dataset A look like:

Date AZWMTG
1/1/201510012
1/2/2015***
1/3/2015***
1/4/2015***
1/5/2015***
1/6/2015***
1/7/2015***
1/8/2015***

Any suggestions?


Accepted Solutions
Solution
‎01-23-2015 01:02 PM
Super Contributor
Posts: 578

Re: How to replace a row from another table

proc sql;

update dataset_a t1

set

     az=(select az from dataset_b where date=t1.date),

     wm=(select wm from dataset_b where date=t1.date),

     tg = (select tg from dataset_b where date=t1.date)

where exists (select * from dataset_b where date=t1.date);

quit;

View solution in original post


All Replies
Solution
‎01-23-2015 01:02 PM
Super Contributor
Posts: 578

Re: How to replace a row from another table

proc sql;

update dataset_a t1

set

     az=(select az from dataset_b where date=t1.date),

     wm=(select wm from dataset_b where date=t1.date),

     tg = (select tg from dataset_b where date=t1.date)

where exists (select * from dataset_b where date=t1.date);

quit;

Occasional Contributor
Posts: 15

Re: How to replace a row from another table

thanks but looks some error

Occasional Contributor
Posts: 15

Re: How to replace a row from another table

Never mind, I forgot to delete comma.

Super User
Super User
Posts: 6,498

Re: How to replace a row from another table

Not sure why people insist on putting commas at the end of the line instead of the beginning.  They are much harder to see out there.

Super User
Posts: 9,671

Re: How to replace a row from another table

Since you already have a index variable DATE, why not use MERGE statement.

data want;
 merge A B;
 by date;
run;
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 557 views
  • 0 likes
  • 4 in conversation