%CMPRES and %QCMPRES Autocall Macros

Compress multiple blanks and remove leading and trailing blanks.
Type: Autocall macros
Requirement: MAUTOSOURCE system option

Syntax

%CMPRES (text | text expression)
%QCMPRES (text | text expression)

Details

Note: Autocall macros are included in a library supplied by SAS Institute. 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 CMPRES and QCMPRES macros compress multiple blanks and remove leading and trailing blanks. If the argument might contain a special character or mnemonic operator, listed below, use %QCMPRES.
CMPRES returns an unquoted result, even if the argument is quoted. QCMPRES 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 Unnecessary Blanks with %CMPRES

%macro createft;
   %let footnote="The result of &x &op &y is %eval(&x &op &y).";
   footnote1 &footnote;
   footnote2 %cmpres(&footnote);
%mend createft;
data _null_;
   x=5;
   y=10;
   call symput('x',x);    /* Uses BEST12. format */
   call symput('y',y);    /* Uses BEST12. format */
   call symput('op','+'); /* Uses $1. format     */
run;
%createft
The CREATEFT macro generates two footnote statements.
FOOTNOTE1 "The result of 5 + _________10 is _________15.";
FOOTNOTE2 "The result of 5 + 10 is 15.";

Example 2: Contrasting %QCMPRES and %CMPRES

%let x=5;
%let y=10;
%let a=%nrstr(%eval(&x   +   &y));
%put QCMPRES: %qcmpres(&a);
%put CMPRES: %cmpres(&a);
The %PUT statements write the following lines to the log:
QCMPRES: %eval(&x + &y)
CMPRES: 15