The `%mf_getquotedstr` macro takes an input string (`IN_STR`) and transforms it into a new string where each element is enclosed in quotes (single, double, or none) and separated by a specified delimiter. Parameters include:
`IN_STR`: The unquoted input string, delimited by spaces (default).
`DLM`: The delimiter to apply to the output string (comma by default).
`QUOTE`: The type of quotes to apply (S for single, D for double, N for none). Any other value will be used as the quoting character.
`indlm`: The delimiter used in the input string (space by default).
The process involves iterating through each 'word' of the input string, applying the specified quotes, removing superfluous spaces around each word (`%qtrim`), and then assembling the new string with the output delimiter. If the input string is empty, it returns two empty quotes (depending on the specified type).
Data Analysis
Type : NONE
The macro operates exclusively on character strings provided as parameters. It neither accesses nor creates SAS datasets, nor does it depend on external data (files, tables).
1 Code Block
MACRO
Explanation : This block defines the `%mf_getquotedstr` macro which processes an input string. It starts by determining the quoting character to use, converting 'S' to a single quote (`byte(39)`) and 'D' to a double quote (`byte(34)`) via `%qsysfunc`. It initializes a local variable `i` to iterate through the input string `IN_STR` using a `%do %while` loop and the `%qscan` function to extract each element according to the input delimiter `indlm`. Each element is then quoted and cleaned of excess spaces with `%qtrim`. The first element initializes the `buffer`, subsequent ones are added with the specified `DLM`. Finally, `%sysfunc(coalescec())` is used to handle the case where the input string is empty, returning two quotes. The final result is the `&buffer` string.
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.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.