Published on :
Macro CREATION_INTERNE

SAS Macro for Comma Removal

This code is also available in: Deutsch Español Français
This SAS© macro, named `nocommas`, is designed to translate all commas present in an input character string into spaces. It uses the `translate` function to perform the replacement and `qsubstr` to handle the positional parameter call syntax. The objective is to clean a string before its use by another macro or function, without performing additional 'cleaning' (such as removing multiple spaces or compressing consecutive spaces). It should be used with a single positional parameter.
Data Analysis

Type : CREATION_INTERNE


The macro operates on a character string provided as a positional parameter during its call. No external or internal data (SASHELP) is read by the macro itself. Data is processed directly from the macro call arguments.

1 Code Block
MACRO nocommas
Explanation :
This block defines the `%nocommas` macro. The `PARMBUFF` option allows the macro to access the complete character string passed as a parameter, including parentheses. The `%SYSFUNC(TRANSLATE(&SYSPBUFF, %STR( ), %STR(,)))` function is used to replace all occurrences of the comma character (`,`) with a space (` `) in the `&SYSPBUFF` string. Then, `%QSUBSTR(..., 2, %LENGTH(&SYSPBUFF)-2)` extracts a substring from the result, removing the first and last characters (generally corresponding to the `%` of the macro call and the ending `;`, or the parentheses enclosing the parameter) to obtain only the processed string.
Copied!
1%put MACRO CALLED: nocommas v1.0;
2 
3%macro nocommas/parmbuff;
4%qsubstr(%sysfunc(translate(&syspbuff,%str( ),%str(,))),2,%LENGTH(&syspbuff)-2)
5%mend nocommas;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : This is public domain software. No guarantee as to suitability or accuracy is given or implied. User uses this code entirely at their own risk.