Using formats will be faster if table EQ3 is not too large, as this conserves the table order and avoids sorting the table again. Thousands of values is fine. If you have millions of values don't bother.

To avoid re-sorting, a hash table is the next choice if you have many values.

It is a matter of volume.

Otherwise, your existing code should be faster if you remove the proc sort and add order by instead.

Re: how to merge two dataset more efficiently

It's possible that the FORMAT statement is intended to reorder the columns. If so, getting the right order would require a small change to the program. Also notice the small correction I added.

If Y is character, a lot depends on the range of values. In some cases, a wider array could be used, with a formula to translate from letter+number to a unique integer value. But that's really what a hash table is for. An informat based on eq3 would also be possible, to be created using a CNTLIN= data set to PROC FORMAT. Sorry to say, you would need to look up some of the details there. But the DATA step would be easy:

data eq;

set eq2;

v = input(y, myform.);

run;

In this case, MYFORM. is the name of the informat that your program creates using a CNTLIN= data set to PROC FORMAT.