That works well as well and I find sysfunc calls to functions more predicatable. I used %trim because it is more straight foward in this situation.
You probably know this, but be aware that compress is not the same as trim and it will remove all blanks, not just the trailing blanks that the "into" statement generates. Probably not an issue in this case, but since you are using worksheet names, it might be.
------------------------------
data tabnaes;
table_name = "Hello World ";
run;
proc sql;
select table_name into:wksht from tabnaes; quit;
%put |%sysfunc(compress(&wksht))|;
%put |%sysfunc(trim(&wksht))|;
%put |%trim(&wksht)|;
------------------- result --------------------
|HelloWorld|
|Hello World|
|Hello World|
-----------------------------------------------
Curtis