SAS Tip: Strip Blanks from PROC SQL-Created Macro Variable Values (Daily tip for 2025-Mar-16)


A macro variable created with PROC SQL from a numeric variable or function contains 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 to strip blanks:

proc sql;
select count(*) into :howmany trimmed from SASHELP.CLASS;
quit;
%put |&howmany|;

|19|

 

 See the documentation for the INTO clause here.


Thanks to Mike Zdeb for sharing this tip on sasCommunity.org.

READ this complete tip   Visit a random SAS tip

Start a topic
About these Tips
A "SAS tip" is a basic unit of information exchange between SAS users. The tips on this board come from sasCommunity.org, from SAS user conferences, from SAS blogs, and from freelance contributions from SAS users like you. We hope that you're able to always learn something new here!


» How you can contribute


Tip-o-meter: 65 tips