SAS macro includes guards

In other programming languages, such as C ++, enable security devices to prevent multiple inclusions of the same code.

Like this in C ++:

#ifndef FOO_INCLUDED
#define FOO_INCLUDED
....
#endif

Does it make sense to create built-in guards in the definition of SAS macro functions? And how should this be done?

+3
source share
2 answers

%SYMEXIST(macro-var-name), , -var, %IF , %IF . , , . , , , , .

%macro wrapper;
  %if %symexist(foo_defined) %then %return;
  %macro foo;
    %global foo_defined;
    %let foo_defined = 1;
    %put i am foo; 
  %mend foo;
%mend  wrapper;

%*-- tests --*;
options mcompilenote=all;
%symdel foo_defined;

%*-- first time it will define %foo --*;
%wrapper
%foo
/* on log
NOTE: The macro FOO completed compilation without errors.
      6 instructions 108 bytes.
i am foo
*/

%*-- second time it will not --*;
%wrapper
%foo
/* on log
(no notes on macro compilation)
i am foo
*/

SAS , (/ ) . , , , . (gory) : http://support.sas.com/resources/papers/proceedings09/076-2009.pdf

+3

NOMREPLACE, .

, ( ) . , , , . , .

+2

Source: https://habr.com/ru/post/1718699/


All Articles