BookmarkSubscribeRSS Feed
Num19
Calcite | Level 5

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.

22 REPLIES 22
novinosrin
Tourmaline | Level 20

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.;



Reeza
Super User

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.


 

Num19
Calcite | Level 5

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.

novinosrin
Tourmaline | Level 20

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);

ballardw
Super User

@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.

WarrenKuhfeld
Rhodochrosite | Level 12

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.

Num19
Calcite | Level 5

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.
😞

novinosrin
Tourmaline | Level 20

Mate!, use %sysevalf  instead of %eval

Reeza
Super User

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.

 

 

Reeza
Super User
And n_max in the macro list versus nmax used in the code.....
Num19
Calcite | Level 5

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.

novinosrin
Tourmaline | Level 20

problem is this 

  %let norm=0; causing vairable name issue hahahahha
novinosrin
Tourmaline | Level 20

that is causing error in macro var creation here 

    %let &norm=%module_2(&u.,&v.);

all same names begin with a letter or underscore 

Num19
Calcite | Level 5

No error displayed but I have nothing displayed by the macro

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 22 replies
  • 2345 views
  • 3 likes
  • 6 in conversation