%TRIM and %QTRIM Autocall Macro

Trim trailing blanks.
Type: Autocall macro
Requirement: MAUTOSOURCE system option

Syntax

%TRIM(text | text expression)
%QTRIM(text | text expression)

Details

Note: Autocall macros are included in a library supplied by SAS. This library might not be installed at your site or might be a site-specific version. If you cannot access this macro or if you want to find out if it is a site-specific version, see your on-site SAS support personnel. For more information, see Storing and Reusing Macros.
The TRIM macro and the QTRIM macro both trim trailing blanks. If the argument contains a special character or mnemonic operator, listed below, use %QTRIM.
QTRIM produces a result with the following special characters and mnemonic operators masked so the macro processor interprets them as text instead of as elements of the macro language:
& % ' " ( ) + − * / < > = ¬ ∘ ~ ; , #  blank
AND OR NOT EQ NE LE LT GE GT IN

Examples

Example 1: Removing Trailing Blanks

In this example, the TRIM autocall macro removes the trailing blanks from a message that is written to the SAS log.
%macro numobs(dsn);
%local num;
data _null_;
   set &dsn nobs=count;
   call symput('num', left(put(count,8.)));
   stop;
   run;
    %if &num eq 0 %then
       %put There were NO observations in %upcase(&dsn).;
    %else
       %put There were %trim(&num) observations in %upcase(&dsn).;
%mend numobs;
%numobs(sample)
Invoking the NUMOBS macro generates the following statements:
DATA _NULL_; 
SET SAMPLE NOBS=COUNT;
CALL SYMPUT('num', LEFT(PUT(COUNT,8.)));
STOP;
RUN;
If the data set SAMPLE contains six observations, then the %PUT statement writes this line to the SAS log:
There were 6 observations in SAMPLE.

Example 2: Contrasting %TRIM and %QTRIM

These statements are executed January 28, 1999:
%let date=%nrstr(   &sysdate   );
%put *&date* *%qtrim(&date)* *%trim(&date)*;
The %PUT statement writes this line to the SAS log:
*   &sysdate   * *   &sysdate* *   28JAN99*