Monday, March 27, 2017

READONLY macro variable

READONLY macro variable is new feature of SAS 9.4. It can be defined as global or local like normal macro variable. However, it has different behaviors as follows:
1. As to global READONLY macro variable, it can not be changed or deleted once created.
2. Global READONLY macro variable is unique and can not be overlapped by local READONLY one.
3. The READONLY macro variable can not overwrite existing normal one

* Sample 1;
%global/readonly mv_ro=1;
%symdel mv_ro; /* ERROR: The variable MV_RO was declared READONLY and cannot be deleted */

* Sample 2;
%macro test;
    %local/readonly mv_ro=2; /* ERROR: The variable MV_RO was previously declared as READONLY and cannot be re-declared. */
%mend;
%test

* Sample 3;
%global mv;
%let mv=1;
%global/readonly mv=2; /* ERROR: The variable MV was previously declared and cannot be made READONLY. */

No comments: