The %GLOBAL statement makes a symbol (usually called a macro variable) in the GLOBAL symbol table and has nothing to do with actual variables. There is no such thing as a "global variable" in SAS. A variable can only exist in a dataset.
The macro processor executes while the program text is being read in and before it is passed to the actual SAS language processor. So placing a %GLOBAL statement in the middle of a data step will just confuse the humans reading the code. The %GLOBAL statement will be executed by the macro processor before the SAS language processor has finished figuring out how to build the DATA step, and so definitely before the DATA step can run. So just place the %GLOBAL statement before the DATA statement so it is clearer to the humans reading the code.
If you want the data step to set the a value into a macro variable use the CALL SYMPUTX() method. So this code if run today would put the string 29OCT2025 into a GLOBAL macro variable named QSTART.
data _null_;
call symputx('qstart',put(intnx('quarter',date(),-1),date9.,'G');
run;
To then use that to generate the WHERE statement in your later code you would need to add something to convert that string into an actual date value. For example you could use it to generate a date literal.
where sampdate ge "&q_start"d ;
... View more