Chapter Contents

Previous

Next
%TRIM and %QTRIM

%TRIM and %QTRIM



Trim trailing blanks

Type: Autocall macro
Requires: MAUTOSOURCE system option


Syntax
Details
Examples
Example 1: Removing Trailing Blanks
Example 2: Contrasting %TRIM and %QTRIM

Syntax

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

Note:   Autocall macros are included in a library supplied by SAS Institute. This library may not be installed at your site or may 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 SAS Software Consultant. For more information, see Chapter 9 in SAS Macro Language: Reference.  [cautionend]


Details

The TRIM macro and the QTRIM macro both trim trailing blanks. If the argument might contain 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


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*


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.