Hi,
Running this code
data T;
retain X1SPACE X2SPACE 'datavalue' Y1SPACE Y2SPACE 'datapercent' FUNCTION 'line';
X1=13; X2=15; Y1=25; Y2=50; output;
X1=11; X2=13; Y1SPACE ='datavalue'; Y2SPACE ='datavalue'; YC1='Alice'; YC2='Alice'; output;
run;
proc sgplot data=SASHELP.CLASS sganno=T;
scatter x=AGE y=NAME;
run;
WARNING: DrawLine statement has missing/invalid value for position (X or Y). Draw statement discarded.
output
lines in the data step results in the remaining line being drawn without issue.
Solution: I answered my own question and contacted tech support for them to create a defect entry, or at least generate a usage note describing this absurd behaviour.
I answered my own question.
I need to set Y1 and Y2 to missing before Y1C and Y2C are used.
Why oh why?
When space is datavalue
and the variable is character, why does SAS try to read Y1 and Y2 instead of Y1C and Y2C? And then throw a fit is that value is not missing?
In situations that involve switching drawing spaces, you might want to consider using the %SGANNO macros: SAS Help Center: SG Annotation Function Dictionary
The macros include a RESET="ALL" option, which clears values left over from other calls. For example, your program can be rewritten by using the %SGLINE macro, as follows:
%SGANNO
data T2;
%sgline(x1space='datavalue',
x2space='datavalue',
y1space='datapercent',
y2space='datapercent',
X1=13, X2=15, Y1=25, Y2=50);
%sgline(drawspace='datavalue',
X1=11, X2=13, YC1='Alice', YC2='Alice',
reset="all");
run;
proc sgplot data=SASHELP.CLASS sganno=T2;
scatter x=AGE y=NAME;
run;
The %sganno
macros present no interest to me. Among the reasons:
1. It's not easier to write
%sgtext( X1=50, Y1=50, LABEL='Player on court');
than
X1=50; Y1=50; LABEL='Player on court'; output;
2. You need to rewrite everything each time, you can't set a variable to use for several annotations like
X1=50;
%sgtext( Y1=50, LABEL='Player on court'); * DOES NOT WORK;
%sgtext( Y1=75, LABEL='Missed shots');
3. The macros break working code. If you try to mix %sganno
and regular output
, you quickly run into trouble.
data ANNO;
FUNCTION='text'; X1=50; Y1=50; LABEL='On-court'; output;
FUNCTION='line'; X1=25; X2=75; Y1=80; Y2=Y1; output;
run;
works but
data ANNO;
%sgtext( X1=50, Y1=50, LABEL='On-court');
FUNCTION='line'; X1=25; X2=75; Y1=80; Y2=Y1; output;
run;
generates
WARNING: The LINE function is missing required column. The function will be ignored.
which is NOT a helpful message.
The coded columns are exactly the same.
All in all, not worth the trouble. The plethora of variable names compared to %anno
are painful enough, no need to add more pain.
Solution: I answered my own question and contacted tech support for them to create a defect entry, or at least generate a usage note describing this absurd behaviour.
Fyi a defect has been raised. Hopefully his gets fixed.
I've reported this problem to development for fixing in a future release. Until that time, you'll need to use your circumvention of setting the Y1/Y2 values to missing.
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
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.