March 25 (Reuters) - Merck MRK.N said on Wednesday it would buy biotech Terns Pharma TERN.O in a deal valued at up to $6.7 billion, as the drugmaker races to bolster its cancer pipeline ahead of the looming patent loss for its blockbuster therapy Keytruda.