BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8
How to trim or delete trailing blanks in the macro whskt?
proc sql;
select table_name into:wksht from tabnaes;
quit;
%put &wksht.;
6 REPLIES 6
CurtisMack
Fluorite | Level 6
data tabnaes;
table_name = "Hello World ";
run;

proc sql;
select table_name into:wksht from tabnaes; quit;
%let wksht = %trim(&wksht);
%put |&wksht.|;
SASPhile
Quartz | Level 8
Thanks curtis.
I used this one:
(select * from [%sysfunc(compress(&wksht))]);
CurtisMack
Fluorite | Level 6
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
SASPhile
Quartz | Level 8
Looks like %trim is more appropriate than compress function in my case.Thanks for the advice anticipating the situations which will arise in the future.
CurtisMack
Fluorite | Level 6
Actually, if you want those multy word spreadsheet names to really work, you will need to enclose them in single quotes followed by the letter n. like this.

'tmp stuff$'n

Here is a way to get that quoting right:
------------------------------------------

data tabnaes;
table_name = "tmp stuff$ ";
run;

libname myxls excel "c:\temp\temp.xls";

proc sql;
select table_name into:wksht from tabnaes; quit;
%let wksht = %str(%')%qsysfunc(trim(&wksht))%str(%')n;
quit;

data junk;
set myxls.%unquote(&wksht);
run;
SASPhile
Quartz | Level 8
I will take that into consideration Curtis.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 894 views
  • 0 likes
  • 2 in conversation