BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
genemroz
Quartz | Level 8

Esteemed Advisers:

I'm having an issue with Macros.

 

The code below runs two instances of a routine to draw a polygon.

In Macro Test A, I use two macros statements. The first, &RoI, sets the size of Region of Interest and is used to reference the appropriate dataset. The second, &Corner, sets the locations of the corners of the RoI in the Annotation Dataset used to construct the polygon. The result (see attached pdf), shown as a plot labeled Macro Test A, displays the polygon as expected.

 

In Macro Test B, I also use two macros, but in this case, &Corner is defined in terms of &RoI. The result (see attached pdf), shown in the plot labeled Macro Test B shows that the polygon is not drawn. Perhaps a macro can't reference another macro? If so, is there another way to automatically set the corners of the polygon from &RoI?

 

Thanks for your help.

 

Gee

 

 

/*MACRO TEST A*/
/*Create macro to select dataset for Region of Interest (work.test&RoI)*/
%LET RoI=460;
/*Create macro to locate corners of Region of Interest for polygon annotation*/
%LET Corner=230;
/*Annotation dataset for region of interest polygon*/
data anno_poly;
	length xc1 yc1 $10 function $50;
	linethickness=2;
	layer='front';
	x1space='datavalue';
	y1space='datavalue';
	function='polygon';
	xc1='-&Corner';
	yc1='-&Corner';
	output;
	function='polycont';
	xc1='&Corner';
	yc1='-&Corner';
	output;
	xc1='&Corner';
	yc1='&Corner';
	output;
	xc1='-&Corner';
	yc1='&Corner';
	output;
	data work.test&RoI;
	do ty=1 to 400 by 10;
	do tx=1 to 400 by 10;
	k=0;
	end;
	end;
	ods graphics / reset width=6.4in height=6.4in imagemap;
	proc sgplot data=work.test&RoI sganno=anno_poly aspect=1;
	title height=12pt "Macro Test A";
	heatmapparm x=tx y=ty colorgroup=k;
	xaxis label='KM' valuesrotate=vertical grid values=(-400 to 400 by 25) 
		fitpolicy=rotatethin;
	yaxis label='KM' grid values=(-400 to 400 by 25) fitpolicy=thin;
run;

/*MACRO TEST B*/
/*Create macro to select dataset for Region of Interest (work.test&RoI)*/
%LET RoI=460;
/*Create macro to locate corners of Region of Interest for polygon annotation*/
%LET Corner=&RoI/2;
/*Annotation dataset for region of interest polygon*/
data anno_poly;
	length xc1 yc1 $10 function $50;
	linethickness=2;
	layer='front';
	x1space='datavalue';
	y1space='datavalue';
	function='polygon';
	xc1='-&Corner';
	yc1='-&Corner';
	output;
	function='polycont';
	xc1='&Corner';
	yc1='-&Corner';
	output;
	xc1='&Corner';
	yc1='&Corner';
	output;
	xc1='-&Corner';
	yc1='&Corner';
	output;
	data work.test&roi;
	do ty=1 to 400 by 10;
	do tx=1 to 400 by 10;
	k=0;
	end;
	end;
	ods graphics / reset width=6.4in height=6.4in imagemap;
	proc sgplot data=work.test&roi sganno=anno_poly aspect=1;
	title height=12pt "Macro Test B";
	heatmapparm x=tx y=ty colorgroup=k;
	xaxis label='KM' valuesrotate=vertical grid values=(-400 to 400 by 25) 
		fitpolicy=rotatethin;
	yaxis label='KM' grid values=(-400 to 400 by 25) fitpolicy=thin;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
Instead of this:
%LET Corner=&RoI/2; should be:

Try:
%let corner =%sysevalf(&rol2/2);

(or %EVAL, check the docs for the difference and see which makes sense for you)

For macro questions you should also include your log, after having run your code with the MPRINT option on. This will show you how your macro variables are resolving and I'll bet that the second one shows that the corner variable is not resolving correctly.

View solution in original post

3 REPLIES 3
Reeza
Super User
Instead of this:
%LET Corner=&RoI/2; should be:

Try:
%let corner =%sysevalf(&rol2/2);

(or %EVAL, check the docs for the difference and see which makes sense for you)

For macro questions you should also include your log, after having run your code with the MPRINT option on. This will show you how your macro variables are resolving and I'll bet that the second one shows that the corner variable is not resolving correctly.
genemroz
Quartz | Level 8
Perfect! Thanks so much!

Gene
Reeza
Super User
And as mentioned previously you're not using macros here, just macro variables. There is a significant difference.
Add this to the top of any program you're using with macro variables/macros to get more information in your log.

options mprint symbolgen;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 3 replies
  • 467 views
  • 1 like
  • 2 in conversation