Published on :
Macro CREATION_INTERNE

AHGwords Macro - List Generation by Substitution

This code is also available in: Deutsch Español Français
The `AHGwords` macro takes a word pattern (`word`) and an iterator (`n`). If the pattern does not contain the character ' @code_sas©/16.4'.sas©, it is appended to the end. The macro detects if `n` is a scalar (via the external macro `%AHGcount`) or a list. If it is a scalar, it generates a numeric sequence starting from the defined `base`. If it is a list, it iterates over each element of `n` to perform the substitution. The result is inserted directly into the code stream (text generation).
Data Analysis

Type : CREATION_INTERNE


The processing is purely macro-textual and does not manipulate any SAS tables.

1 Code Block
MACRO
Explanation :
Macro definition. It prepares the word pattern, determines the iteration type (numeric or list) by calling `%AHGcount`, then executes a `%do` loop to generate the modified strings via `tranwrd`.
Copied!
1%macro AHGwords(word,n,base=1);
2%local AHG4I;
3%IF not %index(&word, @) %THEN %let word=&word @;
4%IF %AHGcount(&n)=1 %THEN
5 %DO AHG4I=%eval(&base) %to %eval(&n+&base-1);
6 %sysfunc(tranwrd(&word, @,&AHG4i))
7 %END;
8%ELSE
9 %DO AHG4i=1 %to %AHGcount(&n) ;
10 %sysfunc(tranwrd(&word, @,%scan(&n,&AHG4i)))
11 %END;
12 
13%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.