Any help in making the below program work would be great. I get error only when I put %do i = 1 %to 4; ,&&a&i %end; in the sum function. I need to dynamically add values of some macro variables there.
%macro testa;
%let a1 = 2;
%let a2 = 0;
%let a3 = 0;
%let a4 = 0;
%do v = 1 %to 10;
%do %while(1<2 ) ;
%if %sysfunc(sum(0 %do i = 1 %to 4; ,&&a&i %end;))<6 %then %do;
data a&v;
a=&v;
run;
%goto leave;
%end; /*End of %if statement*/
%else %do;
data _null_;
a=sleep(1,1);
run;
%end;
%end; /*end of while*/
%leave:
%end; /*end of v*/
%mend testa;
If you are strictly using integers then you could replace %SYSEVALF() with %EVAL().
%let suma = 0;
%do i=1 %to 4 ;
%let suma=%sysevalf(&suma + &&a&i) ;
%end;
%if %sysevalf(&suma < 6) %then %do;
If you are strictly using integers then you could replace %SYSEVALF() with %EVAL().
%let suma = 0;
%do i=1 %to 4 ;
%let suma=%sysevalf(&suma + &&a&i) ;
%end;
%if %sysevalf(&suma < 6) %then %do;
Thanks Tom, I created a work around using your first comment.
If your upper limit is hard coded then it is probably easier to just spell it out.
%if %sysfunc(sum(0,&a1,&a2,&a3,&a4))<6 %then %do;
or
%if ((0 + &a1 + &a2 + &a3 + &a4)<6) %then %do;
Thanks a lot for your response.
My upper limit is hard coded but how many &a1...&an will be there that varies on each run and is determined dynamically. Also if one of the &&a&i has null then using + will give me null that is why I wanted to use sum() function.
Depending on how you are creating them you might want to make sure that the macro variables have a period instead of empty string in that case.
For example this will be true it you create them from data step variables.
data _null_;
a1=1; a2=2 ; a3=.; a4=.;
call symputx('a1',a1);
call symputx('a2',a2);
call symputx('a3',a3);
call symputx('a4',a4);
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.