Desktop productivity for business analysts and programmers

EG trailing blanks issue

Frequent Contributor
Posts: 115

EG trailing blanks issue

I am using sql query to remove the leading and trailing blanks then store in macro variables. but its not removing by using trim function. any alternate way to remove the trailing spaces before load into macro variable

18 Proc sql;

19 Select Button_name, TRIM(Trigger_button), Trigger_date into :Button_name, :Trigger_button, :Trigger_date

20 from ddf_cont.Master_timeline_trig

21 where Order_no=&order_no;

22 quit;

NOTE: PROCEDURE SQL used (Total process time):

real time 0.00 seconds

cpu time 0.02 seconds


24 %put &Button_name &Trigger_button &Trigger_date;

3.4 3.4 Prepare and load data for PRESOP forms                                                                                        06MAR2012

Super User
Posts: 5,366

EG trailing blanks issue


Are you sure you have trailing blanks?  Perhaps you have leading blanks in &Trigger_date.

Try this variation, replacing the first mention of Trigger_date with:


Good luck.

Super User
Posts: 9,867

EG trailing blanks issue

%let Button_name=%trim(&Button_name);

Trusted Advisor
Posts: 1,295

EG trailing blanks issue

Hi There,

Leading and trailing blanks are not trimmed from values before they are stored in macro variables using the SQL into : method when creating a singular macro variable (as opposed to a list of macro variables or separated by a character where they are trimmed) as documented at

If you want them to be removed then you need to add the following %let statements after your proc sql code as leading and trailing blanks on the right hand side of the equals sign are are ignored with the %let statement as documented here:

Proc sql;

Select Button_name, TRIM(Trigger_button), Trigger_date into :Button_name, :Trigger_button, :Trigger_date

from ddf_cont.Master_timeline_trig

where Order_no=&order_no;


%let button_name=&button_name;

%let trigger_button=&trigger_button;

%let tigger_date=&trigger_date;



Super User
Posts: 5,366

EG trailing blanks issue


I shouldn't be, but I'm shocked to find that you're right.  If anyone is interested, here's the test program I ran to confirm:

data test;
length city $ 30;

proc sql noprint;
select city, trim(city) into : all, : trimmed from test;

%put **&all** ##&trimmed##;


Posts: 45

Re: EG trailing blanks issue

This has probably been documented in other posts....

With SAS 9.3 there is a new option allowed on the INTO clause - TRIMMED

which follows the macro name and will remove leading and trailing blanks

Proc SQL;

SELECT value INTO :var TRIMMED FROM work.dsn;


INTO clause

What's new in the SAS 9.3 SQL Procedure

Ask a Question
Discussion stats
  • 5 replies
  • 5 in conversation