The `AHGvar2arr` macro loads the content of a data column (`var`) from a table (`dsn`) into global macro variables named with a prefix (`arrPre`) and an index (e.g., PRE1, PRE2...). It handles prior cleanup via an external macro `%AHGdel`, the initialization of global variables up to a given dimension (`dim`), and dynamic assignment via a Data Step and `CALL SYMPUT`. The total number of elements is stored in a variable with the `_n` suffix.
Data Analysis
Type : EXTERNE
The data source is dynamically defined by the macro parameter `dsn` during the call.
1 Code Block
MACRO
Explanation : Macro definition: global variables are declared via a loop, then a _NULL_ Data Step is executed to read the source table and create the corresponding macro variables via CALL SYMPUT.
Copied!
%macro AHGvar2arr(dsn,var,arrPre,dim=100);
%AHGdel(&arrpre,like=1);
%global &arrPre._n;
%local i;
%do i=1 %to &dim;
%global &arrPRE&i;
%end;
data _null_;
set &dsn end=end;
call symput(strip("&arrpre"||%AHGputn(_n_)),strip(&var));
if end then call symput("&arrPre._n",strip(put(_n_,best.)) );
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.