Published on :
Macro MIXED

Sans titre

This code is also available in: Deutsch Español Français
Awaiting validation
This macro iterates over a list of target variable names (`toVars`) and uses the `scan` function to extract the corresponding segments from the source variable (`inVar`) separated by a delimiter (`dlm`, default is '@'). It generates a DATA step to perform this transformation. It optionally handles the deletion of the source variable and the definition of the output dataset. Note: It depends on external utility macros not provided here (`%AHGblank`, `%AHGbarename`, `%AHGcount`).
Data Analysis

Type : MIXED


Data is provided dynamically via the `dsn` parameter when calling the macro.

1 Code Block
DATA STEP Data
Explanation :
Macro definition. It first checks if an output table name is provided, otherwise it derives a name. Then, it initiates a DATA step reading the input table. A `%do` loop dynamically generates assignment statements for each new variable using the `scan` function. Finally, the original variable is dropped if the `drop` parameter is active.
Copied!
1%macro AHGsplitVar(dsn,inVar,toVars,out=,dlm=@,drop=1);
2 %IF %AHGblank(&out) %THEN %let out=%AHGbarename(&dsn);
3 DATA &out;
4 SET &dsn;
5 %local i;
6 %DO i=1 %to %AHGcount(&toVars);
7 %scan(&ToVars,&i)=scan(&inVar,&i,"&dlm");
8 %END;
9 %IF &drop %THEN drop &invar;;
10 RUN;
11%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.