No harm philosophy

Leading principle: Avoid potential conflicts when using the library - Don’t use common names - Don’t change options permanently

Revert user options at end of macro

Example at start of macro:

* Get original option for displaying 262 character warnings and turn it off for the duration of the macro;
%let original_quotelenmax_value = %sysfunc( getoption(quotelenmax) );
option noquotelenmax; 

And then at end of macro:

* Turn options back to original value;
option &original_quotelenmax_value.; 

Files/macros/do file

  • Prefix all macros and file names with alima- or alima_

Dataset/variable names

  • Use tempvar within Stata for temporary variable names
  • Ensure the output in SAS only contains variables of interest, leave intermediate variables in internal datasets
  • Create a library for output within a macro: Note that the libref is limited to 8 characters only!!

Before main part of macro:

%let work_path=%sysfunc(pathname(work));
%let original_dlcreatedir_value = %sysfunc( getoption(dlcreatedir) );
option dlcreatedir; 
libname macdir "&work_path/this-macro-name";

Before end of macro (the library can be left when debug is on):

libname macdir clear;
option &original_dlcreatedir_value;

Macro variables

  • Use locals inside macros, define globals explicitly
31/08/2018