I have a piece of code that creates some numbers that I then assign to global macro variables to use later on. I want to run the piece of code three times, in order to create three versions of the numbers so that I can then use an average of the three numbers rather than the one off.
So I turned the code into a macro and it doesn't work. I tried some much simplified version of the code and that still doesn't work...
Here is the simple version:
input xval $ yval;
%macro mymacro (loop);
call symput (macname, yval*&loop);
> Since your CALL SYMPUT is executed within a macro,
> the macro variables created will be local.
That is not exactly right. There are a few "depends on" that affect the action. Consider the following example. You can get the exact action you desire with SYMPUTX when you specify the symbol table option.
CALL SYMPUTX(macro-variable, value <,symbol-table>);
Having said that I don't think GLOBAL macro variables are the best choice here. I would think about keeping the data in a SAS data set would be better. I would need to see how these variables are being used to make a recomendation.
TEST A What is my scope
WARNING: Attempt to delete macro variable A failed. Variable not found.
175 %macro test;
176 data _null_;
177 call symput('A','What is my scope');
179 %put _global_;
180 %put _local_;
GLOBAL A What is my scope
186 %symdel a;
187 %global a;
188 %macro test(arg);
189 data _null_;
190 call symput('A','What is my scope');
192 %put _global_;
193 %put _local_;
If you need a SAS global macro variable, simply move the RUN; statement to be outside the SAS macro definition. The DOC I referenced shows this condition in action. I tested your code and that works great. Amazing what the DOC can do for you, when referenced. And I found it by doing a Google advanced search below: