Tips:Strip Blanks from PROC SQL-Created Macro Variable Values

From sasCommunity
Jump to: navigation, search

A macro variable created in PROC SQL from a numeric variable or function has leading blanks...

proc sql;
    select count(*) into :howmany
    from sashelp.class;
quit;
%put |&howmany|;
 
|      19|

An easy way to get rid of the leading blanks is as follows...

proc sql;
    select count(*) into :howmany separated by ''
    from sashelp.class;
quit;
%put |&howmany|;
 
|19|

Posted with thanks to Robert Allison.

Since the original post, the TRIMMED option has been added to the INTO clause in PROC SQL. It will also strip blanks.

proc sql;
    select count(*) into :howmany trimmed
    from sashelp.class;
quit;
%put |&howmany|;
 
|19|

....see also

Submitted By Mike Zdeb