Published on :
Macro CREATION_INTERNE

Macro appmvar - Conditional Concatenation of Macro Variables

This code is also available in: Deutsch Español Français
This macro allows concatenating a new string to an accumulating macro variable (for example, to list error messages). It intelligently manages the addition of a separator (default '; ') only if the variable already contains a value and the new string is not empty, thus avoiding superfluous separators at the beginning or end.
Data Analysis

Type : CREATION_INTERNE


The script does not manipulate data tables (datasets); it operates solely on in-memory macro variables.

1 Code Block
MACRO
Explanation :
Macro definition. It evaluates the length of the target macro variable (indirectly referenced by &&&mvar) and the string to append (&append). If both contain data, they are concatenated with the separator. Otherwise, only the non-empty part is returned without a separator.
Copied!
1%put MACRO CALLED: appmvar v1.0;
2 
3%macro appmvar(mvar,append,sep=%str(; ));
4 %IF %LENGTH(&&&mvar) and %LENGTH(&append) %THEN %DO;
5&&&mvar&sep&append
6 %END;
7 %ELSE %IF %LENGTH(&append) %THEN %DO;
8&append
9 %END;
10 %ELSE %DO;
11&&&mvar
12 %END;
13%mend appmvar;
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 : Author: Roland Rashleigh-Berry / Public domain software