0
votes

I am working in SAS Enterprise Guide and want to save the maximum value of a column into a global macro variable.

I already know how to save the maximum value of a column into a regular macro variable:

proc sql; 
   SELECT max(column)
   INTO: macro_variable
   FROM dataIn
   ;
quit;

But how do I get SAS to save the maximum value of the column as a global variable?

Thanks up front for the help.

1

1 Answers

1
votes

If you the SQL query as open code (that is not inside of a macro) then it WILL create a global macro variable. If you ARE running inside of a macro then just add a %GLOBAL statement in front.

proc sql; 
%global macro_variable;
  SELECT max(column)
    INTO :macro_variable
    FROM dataIn
  ;
quit;

Note that if you are attempting to create a GLOBAL macro variable with the same name as an already existing LOCAL macro then the %GLOBAL statement will cause an error.