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