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!
%macro AHGsplitVar(dsn,inVar,toVars,out=,dlm=@,drop=1);
%if %AHGblank(&out) %then %let out=%AHGbarename(&dsn);
data &out;
set &dsn;
%local i;
%do i=1 %to %AHGcount(&toVars);
%scan(&ToVars,&i)=scan(&inVar,&i,"&dlm");
%end;
%if &drop %then drop &invar;;
run;
%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.
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.