Something like (nothing to check with):
data want (drop=val1); merge tablea (in=a) tableb (in=b keep=var1,value1 rename=(value1=val1)); by var1; if a and b then value1=val1; run;
Do be aware that both tablea and b both need to be sorted by var1 beforehand.
Then sort it to an intermediary in WORK and use that for the merge.
@FLINT wrote:
Here the issue is that I cannot sort one of the tables as its a production table
Datastep merge requires that both datasets are sorted by the by variables. This is a hard and fixed rule. There is nothing stopping you making a copy of the datasets, sorting and merging those.
Other alternatives include using a proc sql code block and rewrite the code you have to be base ANSI, maybe something like:
proc sql; create table want as select a.var1, case when b.value1 ne "" then b.value1 else a.value1 end as value1 from tablea a left join tableb b on a.var1=b.var1; quit;
This still of course does the sorts, its just implicit in the SQL parser to do this rather than you writing the code.
Another way could be hash table, not yet had a reason to use these, so look up some of the plenty of examples on the web or here.
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!
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.