Hello,
I want to include the % sign in a text in a dataset as follows:
label=%upcase('%E from FS');
When I pass that text in PROC SGPLOT via SGANNO, I get the following warning message:
WARNING: Apparent invocation of macro E not resolved.
Can you please advice on how to get rid of that message?
I have tried different options, but nothing is working.
Thanks a lot,
A.G.
Hi,
I think the key point is that SGPLOT is doing its own code generation (it has to generate PROC TEMPLATE code in the background). And any time code is being generated, there is the potential for macro triggers to be revealed.
This code replicates your problem. As you say, the DATA step does not see %E as a macro call, because it is hidden by the single quotes. However, the PROC SGPLOT does see the % sign as a macro trigger:
data anno;
function="text";
x1space= 'graphpercent';
y1space= 'graphpercent';
y1=50;
x1=50;
label='%E FROM FS IN ';
run;
proc sgplot data=sashelp.class sganno=anno tmplout="c:\junk\mytmpl.sas";
scatter x=height y=weight ;
run ;
I added the tmplout= option to the proc, so that you can see the code that SGPLOT generated. You can see that it generates a DRAWTEXT statement for the annotation, and the value is in double quotes:
proc template;
define statgraph sgplot;
begingraph / collation=binary;
layout overlay / yaxisopts=(labelFitPolicy=Split) y2axisopts=(labelFitPolicy=Split);
ScatterPlot X=Height Y=Weight / subpixel=off primary=true LegendLabel="Weight" NAME="SCATTER";
DrawText "%E FROM FS IN" / X=50 Y=50 XSPACE=graphpercent YSPACE=graphpercent;
endlayout;
endgraph;
end;
run;
While it looks funny in the DATA step code, one option would be to add %NRSTR() inside the single quotes. This will prevent SGPLOT from seeing the % sign as a macro trigger:
data anno;
function="text";
x1space= 'graphpercent';
y1space= 'graphpercent';
y1=50;
x1=50;
label='%nrstr(%E) FROM FS IN ';
run;
proc sgplot data=sashelp.class sganno=anno tmplout="c:\junk\mytmpl2.sas";
scatter x=height y=weight ;
run ;
because the SGPLOT will generate:
proc template;
define statgraph sgplot;
begingraph / collation=binary;
layout overlay / yaxisopts=(labelFitPolicy=Split) y2axisopts=(labelFitPolicy=Split);
ScatterPlot X=Height Y=Weight / subpixel=off primary=true LegendLabel="Weight" NAME="SCATTER";
DrawText "%nrstr(%E) FROM FS IN" / X=50 Y=50 XSPACE=graphpercent YSPACE=graphpercent;
endlayout;
endgraph;
end;
run;
HTH
Please show the entire code of the steps involved.
It appears that you may be using %upcase in a data step where the function should be Upcase.
The code shown won't run.
label=%upcase('%E from FS.); output;
Missing a ' will cause problems.
Since you are dealing with literal text skip the %UPCASE function
label='%E FROM FS';
The SAS editor tyically uses ctrl+U to capitalize highlighted text.
The %upcase macro function means that things like % and & will get treated differently and it is a separate headache learning about correct usage. Avoid until needed.
@alexgonzalez wrote:
In the previous code also shown below, the missing ' was accidentally deleted when I copied the code from my original code.
label=%upcase('%E from FS.);
output;
I removed the %UPCASE function as you suggested and still getting the warning message.
Additionally, let's say I also want to pass a macro variable into the label as follows:
label="%E FROM FS in &agesex";
Thanks a lot BallardW.
The show WHERE the macro value is created. If you don't want the warning to appear then concatenating text prior that step into a single macro variable would be the answer.
This appears to do what you want without creating the warning messages.
%let agesex = something; %let string = %nrstr(%E FROM FS IN ) &agesex.; %put &string; data junk; x=1; label x ="&string."; run;
You will NOT get a message if you use single quotes around the value. The macro processor ignores macro triggers inside of quoted strings that use single quotes on the outside. So this is fine:
label=upcase('%E from FS.');
Now your new post is probably the code that is giving you the message. If you are doing it in a data step, like the above was used then just split the string into separate strings.
label='%E FROM FS in ' || "&agesex";
If the value of the macro variable AGESEX has % or & and you are using the statement outside of a data step then add some macro quoting. Such as:
%let agesex=40 yr old males;
%let label=%nrstr(%'%%)E FROM FS in &agesex%nrstr(%');
%put &=label;
or if you are in a data step use SYMGET() function to retrieve the macro variable's value.
label='%E FROM FS in ' || symget('agesex');
Hi,
I think the key point is that SGPLOT is doing its own code generation (it has to generate PROC TEMPLATE code in the background). And any time code is being generated, there is the potential for macro triggers to be revealed.
This code replicates your problem. As you say, the DATA step does not see %E as a macro call, because it is hidden by the single quotes. However, the PROC SGPLOT does see the % sign as a macro trigger:
data anno;
function="text";
x1space= 'graphpercent';
y1space= 'graphpercent';
y1=50;
x1=50;
label='%E FROM FS IN ';
run;
proc sgplot data=sashelp.class sganno=anno tmplout="c:\junk\mytmpl.sas";
scatter x=height y=weight ;
run ;
I added the tmplout= option to the proc, so that you can see the code that SGPLOT generated. You can see that it generates a DRAWTEXT statement for the annotation, and the value is in double quotes:
proc template;
define statgraph sgplot;
begingraph / collation=binary;
layout overlay / yaxisopts=(labelFitPolicy=Split) y2axisopts=(labelFitPolicy=Split);
ScatterPlot X=Height Y=Weight / subpixel=off primary=true LegendLabel="Weight" NAME="SCATTER";
DrawText "%E FROM FS IN" / X=50 Y=50 XSPACE=graphpercent YSPACE=graphpercent;
endlayout;
endgraph;
end;
run;
While it looks funny in the DATA step code, one option would be to add %NRSTR() inside the single quotes. This will prevent SGPLOT from seeing the % sign as a macro trigger:
data anno;
function="text";
x1space= 'graphpercent';
y1space= 'graphpercent';
y1=50;
x1=50;
label='%nrstr(%E) FROM FS IN ';
run;
proc sgplot data=sashelp.class sganno=anno tmplout="c:\junk\mytmpl2.sas";
scatter x=height y=weight ;
run ;
because the SGPLOT will generate:
proc template;
define statgraph sgplot;
begingraph / collation=binary;
layout overlay / yaxisopts=(labelFitPolicy=Split) y2axisopts=(labelFitPolicy=Split);
ScatterPlot X=Height Y=Weight / subpixel=off primary=true LegendLabel="Weight" NAME="SCATTER";
DrawText "%nrstr(%E) FROM FS IN" / X=50 Y=50 XSPACE=graphpercent YSPACE=graphpercent;
endlayout;
endgraph;
end;
run;
HTH
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.