Published on :
Administration INTERNAL_CREATION

Lilly Macro Library Refresh

This code is also available in: Deutsch Español Français
Attention : This code requires administrator privileges.
The AHGrefreshlilly macro performs several key operations. First, it uses DATA steps with the `filename pip pipe 'dir ...'` command to list all '.sas©' files present in the 'core' and 'inter' subdirectories of a path defined by the `kanbox` variable. It filters files to exclude 'refreshmac.sas©' and, if specified, to include only the files listed in the 'files' parameter. Each found SAS© file is then dynamically included in the SAS© session via `%include`. Second, the macro initializes network paths (`SAdrive`, `macbackup`) and defines a libname `netmac` pointing to the macro backup directory. It then uses system commands (`x mkdir`, `x copy`) to create a timestamped directory and copy all existing files from the macro library to this new backup directory. Finally, it copies catalogs (likely containing compiled macros) from the temporary `work` catalog to the `netmac` libname (the backup directory), thus ensuring that the macro library is up-to-date and backed up.
Data Analysis

Type : INTERNAL_CREATION


The script does not directly use external SAS datasets. The two 'DATA _NULL_' steps are used to execute system commands and manipulate file paths, without creating persistent datasets. The processed data primarily consists of file metadata (SAS filenames) and access paths.

1 Code Block
DATA STEP
Explanation :
This SAS Data Step block, which does not create a persistent dataset ('_NULL_'), uses the `filename pip pipe 'dir ...'` function to execute the system command 'dir' and list '.sas' filenames in the 'core' directory defined by `kanbox`. Filenames are read one by one. It includes logic to exclude 'refreshmac.sas' and to filter files if the `&files` parameter is provided. For each relevant file, it constructs an `%include` command and executes it dynamically via `call execute`, allowing other macros or SAS code to be included.
Copied!
1 DATA _null_;
2 filename pip pipe "dir "&kanbox\core\*.sas " /b";
3 INFILE pip;
4 LENGTH file $100 com $300;
5 INPUT file ;
6 IF index(file,'refreshmac.sas') THEN return;
7 IF ("&files" ne '') and (not index(upcase("&files"),trim(upcase(file)))) THEN return;
8 com=("%include "&kanbox\core\"||file||"';");
9 put com=;
10 call execute(com);
11 RUN;
2 Code Block
DATA STEP
Explanation :
Similar to the previous block, this second Data Step also uses a 'DATA _NULL_' to dynamically list and include '.sas' files. The only difference is that it targets the 'inter' directory instead of 'core' within the `kanbox` path, performing the same filtering and dynamic inclusion logic for macros or code located in this directory.
Copied!
1 DATA _null_;
2 filename pip pipe "dir "&kanbox\inter\*.sas " /b";
3 INFILE pip;
4 LENGTH file $100 com $300;
5 INPUT file ;
6 IF index(file,'refreshmac.sas') THEN return;
7 IF ("&files" ne '') and (not index(upcase("&files"),trim(upcase(file)))) THEN return;
8 com=("%include "&kanbox\inter\"||file||"';");
9 put com=;
10 call execute(com);
11 RUN;
3 Code Block
Macro and system commands
Explanation :
This block defines local variables for network paths (`SAdrive`, `macbackup`) and allocates a `netmac` libname to the macro backup directory. It then uses two macros (`%AHGdateandtime`, `%AHGpm`) to generate a date/time in the `mydt` variable (not provided, assumed to exist elsewhere). Crucially, it executes system commands via the `x` statement: `x mkdir` to create a new timestamped directory for the backup, and `x copy` to copy existing library files to this new backup directory. Finally, `PROC DATASETS` is used to copy all catalogs (which contain compiled macros) from the temporary 'work' library to the 'netmac' libname, thereby ensuring the macro library is backed up and refreshed.
Copied!
1 %local macbackup;
2 %let SAdrive=\\gh3nas01\gh3nas_sales.grp\LCDDMAC\STATS\SA;
3 %let macbackup=&sadrive\Macro library\Macro learning tool\sas7bcat\mac;
4
5 LIBNAME netmac "&macbackup";
6 %local mydt;
7 %AHGdateandtime(mydt);
8 %AHGpm(mydt);
9
10 x mkdir "&macbackup&mydt";
11 x copy "&macbackup\*.*" "&macbackup&mydt";
12 PROC DATASETS lib=work;
13 copy out=netmac memtype=catalog;
14 RUN;
15 QUIT;
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.