SAS Macro GLOBAL scope

Is there a short way to make ALL macro variables created inside a macro global in scope?

t

%macro x;  
 %global _all_;  * ??? ;  
 %let x=1;  
 %let y=1;  
 %let z=1;  
%mend;
+3
source share
3 answers

The only way I can do this without declaring each macro as global ahead of time, and then make the% let statement, use a macro instead of the% let statement.

% mylet, , . % let , .

.

%global myvar;
%let myvar=2;

...

%mylet(myvar,2);

/* Define a macro to declare variables as global */
%macro mylet(var,value);
  %global &var;
  %let &var.= &value ;
%mend;

/* Test macro */
%macro test;
 %mylet(myvar,2);
 %mylet(myvar2,12);
 %mylet(myvar3,'string');

/* see that they are global inside the macro */
title "Macro scope inside test macro";
proc sql;
    select *
       from dictionary.macros
       where name in('MYVAR','MYVAR2','MYVAR3');
quit;

%mend;
%test;

/* Check to see if they are still global outside the macro */
title "Macro scope outside test macro";
proc sql;
    select *
       from dictionary.macros
       where name in('MYVAR','MYVAR2','MYVAR3');
quit;
+5

, :

%let x=1;  
%let y=1;  
%let z=1; 

, :

%macro x;
  <code here>
%mend x;

:

data _null_;
    set LIB.DSET;
    x = 1;
    call symput('x',x);
run;
+4

, .

call symputx('macvar',macval,'g'); 

.

+3

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


All Articles