BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14


Hello I have the following question.


I have a data set called 'tbl1' which contain fields: x,y1,y2.


Sometimes there another data set called "recovery_tbl' which contain fields: x,w,y1,y2


If in specific field all values are missing(null values in all columns) then If a recovery data set exists it will gather the values from there.

Data tbl1;
input ID  y1  y2;
cards;
1 10 .
2 20 .
3 30 .
4 40 .
5 50 .
;
Run;
Data recovery_tbl;
input ID w y1  y2;
cards;
1 5 10 100
2 6 20 200
3 7 30 300
4 8 40 400
5 9 50 500
;
Run;
PROC SQL;
	create table tbl1_new as
	select a.ID,a.Y1,coalesce(a.Y2,b.Y2) as Y2	   
	from tbl1 as a
	left join recovery_tbl as b
	on a.ID=b.ID
;
QUIT;


Can anyone how to perform this conditional merge. The merge need to be done only if 2 conditions happens: 1-There is a field that all values are null (missing values) 2- A recover table exists

1 REPLY 1
Astounding
PROC Star

Two questions, just to clarify what is needed.

 

If only some of the y2 values are missing from TBL1, would you like to use TBL1 as is (including those missing values)?

 

Are you guaranteed that each table contains exactly one observation per ID?

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 1 reply
  • 931 views
  • 0 likes
  • 2 in conversation