Please, from now on, when there are errors in the log, show us the ENTIRE log for the macro or for the data step. Do not just show us the ERRORs.
The problem is the macro scope. This means that macro variables which are assigned values within a macro (in this case, inside macro %macro1) do not exist outside of this macro.
There are generally 3 ways to fix this:
Regarding #2, this would work to replace %macro1
%let server=SASAPP1;
data _null_;
call symputx("storage_cnt_&server.1",100);
run;
%put &=storage_cnt_&server.1;
/* Repeat with %let serve=SASAPP2 */
Please, from now on, when there are errors in the log, show us the ENTIRE log for the macro or for the data step. Do not just show us the ERRORs.
The problem is the macro scope. This means that macro variables which are assigned values within a macro (in this case, inside macro %macro1) do not exist outside of this macro.
There are generally 3 ways to fix this:
Regarding #2, this would work to replace %macro1
%let server=SASAPP1;
data _null_;
call symputx("storage_cnt_&server.1",100);
run;
%put &=storage_cnt_&server.1;
/* Repeat with %let serve=SASAPP2 */
Macro variable scope.
You create the macro variable in a macro, and if it does not exist in the global table before, it will be local to the macro and vanish once the macro terminates. Use the %GLOBAL statement:
%macro macro1(server1);
data have_&server1.;
storage_cnt=100;
run;
%global storage_cnt_&server1.;
proc sql noprint;
select storage_cnt into :storage_cnt_&server1. from have_&server1.;
quit;
%put storage_cnt_&server1.=&&storage_cnt_&server1.;
%mend macro1;
Make sure the macro variables exist so they don't end up being defined as LOCAL to the macro.
Also do not use ancient CALL SYMPUT() method unless you really have a need to add leading or trailing spaces into the macro variable. Use CALL SYMPUTX().
%let storage_cnt_SASAPP1=;
%let storage_cnt_SASAPP2=;
%macro1(SASAPP1);
%macro1(SASAPP2);
DATA _null_;
total_storage=SUM(&storage_cnt_SASAPP1.,&storage_cnt_SASAPP2.);
call symputX('total_storage',total_storage);
RUN;
%put total_storage=&total_storage.;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.