Published on :
Macro CREATION_INTERNE

Converting Double Quotes and Commas in a String

This code is also available in: Deutsch Español Français
This utility macro, designed as a function, aims to 'clean' a character string. It is particularly useful for preparing strings to be passed as parameters in contexts where syntax is strict, such as when submitting code remotely (`rsubmit`). The macro accepts a single positional parameter containing the string to be processed. It performs two operations: first, it replaces all commas with spaces using `%sysfunc(translate)`. Then, it assumes the string is surrounded by quotes, removes them with `%qsubstr`, and passes the result to an external macro `%dq2sq` which is supposed to handle the conversion of double quotes to single quotes. Therefore, the macro has a dependency on the `%dq2sq` macro, which is not defined in this code.
Data Analysis

Type : CREATION_INTERNE


The macro does not operate on any data tables. The input is a character string provided as a parameter at the time of the call.

1 Code Block
Macro
Explanation :
This block defines the `%dq2sqnc` macro. A message is first written to the log via `%PUT`. The macro uses the `parmbuff` option to capture all parameters positionally. It then uses the `%SYSFUNC` function to call the SAS `TRANSLATE` function to replace commas (`,`) with spaces (` `). The `%QSUBSTR` function is used to remove the first and last characters of the string (assumed to be quotes). The result is then passed as a parameter to another macro, `%dq2sq`, for further processing.
Copied!
1%put MACRO CALLED: dq2sqnc v1.0;
2 
3%macro dq2sqnc/parmbuff;
4%dq2sq(%qsubstr(%sysfunc(translate(&syspbuff,%str( ),%str(,))),2,%LENGTH(&syspbuff)-2))
5%mend dq2sqnc;
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.