Published on :
Macro CREATION_INTERNE

Alignment and Formatting Macro using Regular Expressions

This code is also available in: Deutsch Español Français
This macro iterates over a list of variables provided as a parameter (space-delimited). For each variable, it generates SAS© code (intended to be executed within a DATA step) applying a series of `PRXCHANGE` functions. These transformations aim to standardize spacing around numbers, parentheses, and decimal points. Note that this code depends on an external macro `%AHGcount` not provided here.
Data Analysis

Type : CREATION_INTERNE


The script defines a utility macro. It does not read any data directly but manipulates variables passed as arguments within a calling Data step.

1 Code Block
MACRO
Explanation :
Definition of the `AHGalign` macro. It loops over the provided variable list (`allvar`) using the third-party macro `%AHGcount`. For each variable, it injects four `PRXCHANGE` instructions to: 1) Format numbers followed by parentheses. 2) Add two spaces before single digits. 3) Add one space before two-digit numbers. 4) Remove spaces after a period.
Copied!
1%macro AHGalign(allvar);
2 %local var i;
3 %DO i=1 %to %AHGcount(&allvar);
4 %let var=%scan(&allvar,&i);
5 &var=PRXCHANGE('s/\s*(\d+)\s*\((\S*)\s*\)/\1 (\2)/',-1,&var);
6 &var=PRXCHANGE('s/(\b\d\b)/ \1/',-1,&var);
7 &var=PRXCHANGE('s/(\b\d\d\b)/ \1/',-1,&var);
8 &var=PRXCHANGE('s/(\.\s*)/./',-1,&var);
9 %END;
10%mend;
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.