Hi, I made a program which put the x and y coordonates when a condition is verified but I have an error generated in SAS,
here some informations :
%macro mandelbrot(x_min,x_max,y_min,y_max,pas,seuil,n_max); %let pas_coef=&pas.*100; %let x_min_coef=(&x_min.*100); %let x_max_coef=(&x_max.*100); %let y_min_coef=(&y_min.*100); %let y_max_coef=(&y_max.*100); %let u=0; %let v=0; %do i=&x_min_coef. %to &x_max_coef. by &pas_coef.; %do j=&y_min_coef. %to &y_max_coef. by &pas_coef.; %let n=0; %let u=0; %let v=0; %let &norm=0; %let x_r=%sysevalf(&i./100); %let y_r=%sysevalf(&j./100); %do %while(&norm.<&seuil. and &n.<&nmax.); %let n=%eval(1+&n.); %let u=%sysevalf((&u.)**2-(&v.)**2+&x_r.); %let v=%sysevalf(2*(&u.)*(&v.)+&y_r.); %let &norm=%module_2(&u.,&v.); %end; %if (&norm.<&seuil.) %then %do; proc sql; insert into MANDELBROT values (&x_r.,&y_r.); quit; %end; %end; %end; %mend mandelbrot; %mandelbrot(-2,0.5,-1.1,1.1,0.02,2,30);
The error :
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition
was: &x_max_coef. by &pas_coef.
ERROR: The %TO value of the %DO I loop is invalid.
ERROR: The macro MANDELBROT will stop executing.
should be %by instead of by coz you are using macro language needing macro syntax for the macro processor to recognize
%do i=&x_min_coef. %to &x_max_coef. %by &pas_coef.; %do j=&y_min_coef. %to &y_max_coef. %by &pas_coef.;
A %DO loop likely wants a %BY rather than BY.
@Num19 wrote:
Hi, I made a program which put the x and y coordonates when a condition is verified but I have an error generated in SAS,
here some informations :
%macro mandelbrot(x_min,x_max,y_min,y_max,pas,seuil,n_max); %let pas_coef=&pas.*100; %let x_min_coef=(&x_min.*100); %let x_max_coef=(&x_max.*100); %let y_min_coef=(&y_min.*100); %let y_max_coef=(&y_max.*100); %let u=0; %let v=0; %do i=&x_min_coef. %to &x_max_coef. by &pas_coef.; %do j=&y_min_coef. %to &y_max_coef. by &pas_coef.; %let n=0; %let u=0; %let v=0; %let &norm=0; %let x_r=%sysevalf(&i./100); %let y_r=%sysevalf(&j./100); %do %while(&norm.<&seuil. and &n.<&nmax.); %let n=%eval(1+&n.); %let u=%sysevalf((&u.)**2-(&v.)**2+&x_r.); %let v=%sysevalf(2*(&u.)*(&v.)+&y_r.); %let &norm=%module_2(&u.,&v.); %end; %if (&norm.<&seuil.) %then %do; proc sql; insert into MANDELBROT values (&x_r.,&y_r.); quit; %end; %end; %end; %mend mandelbrot; %mandelbrot(-2,0.5,-1.1,1.1,0.02,2,30);The error :
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition
was: &x_max_coef. by &pas_coef.
ERROR: The %TO value of the %DO I loop is invalid.
ERROR: The macro MANDELBROT will stop executing.
Oh, sorry for that mistake.
Now I have :
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition
was: &x_max_coef.
ERROR: The %TO value of the %DO I loop is invalid.
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition
was: &pas_coef.
ERROR: The %BY value of the %DO I loop is invalid.
ERROR: The macro MANDELBROT will stop executing.
sorry my bad that i didn't notice at the top, you need %eval in your %let assignments
or to be safe %sysevalf
%let pas_coef=&pas.*100;
%let x_min_coef=(&x_min.*100);
%let x_max_coef=(&x_max.*100);
%let y_min_coef=(&y_min.*100);
%let y_max_coef=(&y_max.*100);
@novinosrin wrote:
sorry my bad that i didn't notice at the top, you need %eval in your %let assignments
or to be safe %sysevalf
%let pas_coef=&pas.*100;
%let x_min_coef=(&x_min.*100);
%let x_max_coef=(&x_max.*100);
%let y_min_coef=(&y_min.*100);
%let y_max_coef=(&y_max.*100);
AND
%eval only does integers.
See
2740 %let junk= %eval(0.5 *100); ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: 0.5 *100
Yes you would need:
%let junk= %sysevalf(0.5 *100);
HOWEVER since you are using those values in %do loops ALL the values must be integers on the %do statements. The macro language doesn't work with %do x= .5 %to 10 %by .5;
Of course the question is why are you doing data processing in the macro language to begin with???
Especially to do an INSERT into a set using Proc SQL? I don't know what your %module_2 macro does but I'm willing to be this can all be turned into a data step relatively easily.
I completely agree with @ballardw . You are making this an order of magnitude harder than it needs to be by using the macro language instead of a DATA step.
Error on error I have this one now :
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition
was: 0.02*100
ERROR: The macro MANDELBROT will stop executing.
😞
Mate!, use %sysevalf instead of %eval
1. Replace BY with %BY
2. Set parameters using %SYSEVALF()
3. Fix Norm value declaration (not &norm, remove &).
4. NMAX is undeclared/not calculated???
%macro mandelbrot(x_min,x_max,y_min,y_max,pas,seuil,n_max);
%let pas_coef=%sysevalf(&pas.*100);
%let x_min_coef=%sysevalf(&x_min.*100);
%let x_max_coef=%sysevalf(&x_max.*100);
%let y_min_coef=%sysevalf(&y_min.*100);
%let y_max_coef=%sysevalf(&y_max.*100);
%let u=0;
%let v=0;
%do i=&x_min_coef. %to &x_max_coef. %by &pas_coef.;
%do j=&y_min_coef. %to &y_max_coef. %by &pas_coef.;
%let n=0;
%let u=0;
%let v=0;
%let norm=0;
%let x_r=%sysevalf(&i./100);
%let y_r=%sysevalf(&j./100);
%do %while(&norm.<&seuil. and &n.<&nmax.);
%let n=%eval(1+&n.);
%let u=%sysevalf((&u.)**2-(&v.)**2+&x_r.);
%let v=%sysevalf(2*(&u.)*(&v.)+&y_r.);
%let &norm=%module_2(&u.,&v.);
%end;
%if (&norm.<&seuil.) %then %do;
proc sql;
insert into MANDELBROT values (&x_r.,&y_r.);
quit;
%end;
%end;
%end;
%mend mandelbrot;
%mandelbrot(-2,0.5,-1.1,1.1,0.02,2,30);
A little bit closer....it seems like this would be easier/faster in a data step or PROC IML.
It says NMAX isn't declared, which is true.
I think that's so close, I have this now :
ERROR: Expecting a variable name after %LET.
ERROR: Symbolic variable name 0 must begin with a letter or underscore.
ERROR: The macro MANDELBROT will stop executing.
problem is this
%let norm=0; causing vairable name issue hahahahha
that is causing error in macro var creation here
%let &norm=%module_2(&u.,&v.);
all same names begin with a letter or underscore
No error displayed but I have nothing displayed by the macro
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.