I am trying to use annotate to make a graph of booked rooms. I orginally used function='line' , but I wanted to include shading styles. When I use function='bar' the style is ignored. I get the same result with function='line'. What am I missing here? Here is the code example.
Thank you for taking a look at this.
Stan
data source;
length color text $8. ;
location = 'Rm-01'; starttime='08:00't; endtime='15:30't; color = 'red'; text= 'red'; output;
location = 'Rm-02'; starttime='08:30't; endtime='16:00't; color = 'white'; text= 'white'; output;
location = 'Rm-03'; starttime='08:15't; endtime='15:15't; color = 'blue'; text= 'blue';output;
run;
%let SZ=44;
data anno;
length style $5. ;
length function $12. ;
retain xsys ysys '2' size &SZ color 'orange' BlkHldrLabel ' ';
set source ;
ine=1;
style ='solid';
if color = 'white' then do; style='R2'; color='light grey'; end;
function='move' ; x=StartTime ; yc=location ; output ;
function='bar' ; size=&SZ ; x=EndTime ; yc=location ; output ;
function='label' ; color='white'; size=3 ; style='Arial'; position ='6' ;
x=StartTime ; yc=location; output;
run;
/* Set Symbols and Axes */
symbol1 i=none;
axis1 label=none;
axis2 order=(21600 to 72000 by 3600) minor=none
label=(h=1.5 "Time of Day") Value=(h=1);
/* Plot the Timeline */
proc gplot annotate=anno ;
plot location*EndTime/vaxis=axis1 haxis=axis2 VREVERSE
href= 21600 25200 28800 32400 36000 39600 43200
50400 54000 57600 61200 64800 68400 72000
lhref=4;
format EndTime time5.;
run;
Here's one alternative way to draw/annotate the bars - rather than using the same y-value for the move/bar, use a relative coordinate system, and set the top/right corner of the bar 5% above the bottom/left y (see bold code below):
data source;
length color text $8. ;
location = 'Rm-01'; starttime='08:00't; endtime='15:30't; color = 'red'; text= 'red'; output;
location = 'Rm-02'; starttime='08:30't; endtime='16:00't; color = 'white'; text= 'white'; output;
location = 'Rm-03'; starttime='08:15't; endtime='15:15't; color = 'blue'; text= 'blue';output;
run;
data anno;
length style $5 color $12 function $12;
set source;
xsys='2'; ysys='2'; hsys='3';
style='solid';
if color='white' then do; style='r1'; color='gray99'; end;
function='move'; x=StartTime; ysys='2'; yc=location; output;
function='bar'; x=EndTime; ysys='b'; y=5; line=0; output;
function='label'; color='grau77'; size=4.0; style='Arial'; ysys='2'; position ='c';
x=StartTime ; yc=location; output;
run;
symbol1 i=none;
axis1 label=none offset=(1,4);
axis2 order=(21600 to 72000 by 3600) minor=none label=(h=1.5 "Time of Day") Value=(h=1);
proc gplot data=source annotate=anno;
plot location*EndTime/vaxis=axis1 haxis=axis2 VREVERSE
href= 21600 25200 28800 32400 36000 39600 43200
50400 54000 57600 61200 64800 68400 72000
lhref=4;
format EndTime time5.;
run;
Is "ine" supposed to be "line"? Maybe some values get truncated in the annotate data set, which should look something like this:
OBS FUNCTION X Y HSYS XSYS YSYS STYLE COLOR POSITION SIZE LINE TEXT
1 label 20 85 3 3 3 swissb green 6 6.0 . Sample Annotate Graphics
2 move 28 30 3 3 3 swissb green 6 6.0 . Sample Annotate Graphics
3 draw 68 30 3 3 3 swissb red 6 0.8 1 Sample Annotate Graphics
4 draw 48 70 3 3 3 swissb red 6 0.8 1 Sample Annotate Graphics
5 draw 28 30 3 3 3 swissb red 6 0.8 1 Sample Annotate Graphics
You have a sharp eye. I messed up the cut and paste. Unfortunately, I could not see how to edit a post when I realized that.
Here is a more simplified example, with %annomac and %hbar macros, the internal files and outputs:
As you can see the anno dataset looks correct.
It appears that with character coodinates, you cannot do fills.
Thank you.
Stan
data source;
length barcolor text $8. ;
location = 'Rm-01'; starttime='08:00't; endtime='15:30't; barcolor = 'red'; text= 'red'; output;
location = 'Rm-02'; starttime='08:30't; endtime='16:00't; barcolor = 'white'; text= 'white'; output;
location = 'Rm-03'; starttime='08:15't; endtime='15:15't; barcolor = 'blue'; text= 'blue';output;
run;
options symbolgen;
%let SZ=44;
%annomac;
data anno (rename=(y=yc));
length style $5. ;
length function $12. ;
retain xsys ysys '2' size &SZ ;
set source ;
put location= starttime= endtime= barcolor= text= ;
line=0; style ='Empty'; color=barcolor;
%BAR2(starttime, location, endtime, location, *, line, R5, &SZ);
run;
/* Set Symbols and Axes */
symbol1 i=none;
axis1 label=none;
axis2 order=(21600 to 72000 by 3600) minor=none
label=(h=1.5 "Time of Day") Value=(h=1);
/* Plot the Timeline */
proc gplot annotate=anno ;
plot location*EndTime/vaxis=axis1 haxis=axis2 VREVERSE
href= 21600 25200 28800 32400 36000 39600 43200 46800
50400 54000 57600 61200 64800 68400 72000
lhref=4;
format EndTime time5.;
run;
**** Here is source:
**** Here is anno ****
Here is the output
First your COLOR variable has different length settings, so "light gray" is truncated to "light".
Second IIRC correctly you may need to specify which form of Arial that you want to use. Likely your system has fonts like 'Arial Regular' 'Arial Black' 'Arial Bold' 'Arial Bold Italic' and 'Arial Italic'. It has been a long time since I did any annotate for Proc Gplot but I seem to remember several fonts, Arial among them, that needs the full name.
Have modified your program by making the length of the Color and Style variable longer and used 'Arial Black', a very bold version, to show that the font style is applied, changed "ine" to "line", and reformatted the code a bit. You may need to check your system for the actual spelling of the font a bit more carefully.
data source; length color text $15. ; location = 'Rm-01'; starttime='08:00't; endtime='15:30't; color = 'red'; text= 'red'; output; location = 'Rm-02'; starttime='08:30't; endtime='16:00't; color = 'white'; text= 'white'; output; location = 'Rm-03'; starttime='08:15't; endtime='15:15't; color = 'blue'; text= 'blue';output; run; %let SZ=44; data anno; length style $15. color $15.; length function $12. ; retain xsys ysys '2' size &SZ color 'orange' BlkHldrLabel ' ' ; set source ; line=1; style ='solid'; if color = 'white' then do; style='R2'; color='light grey'; end; function='move' ; x=StartTime ; yc=location ; output ; function='bar' ; size=&SZ ; x=EndTime ; yc=location ; output ; function='label' ; color='white'; size=3 ; style='Arial Black'; position ='6' ; x=StartTime ; yc=location; output; run; /* Set Symbols and Axes */ symbol1 i=none; axis1 label=none; axis2 order=(21600 to 72000 by 3600) minor=none label=(h=1.5 "Time of Day") Value=(h=1); /* Plot the Timeline */ proc gplot annotate=anno ; plot location*EndTime/vaxis=axis1 haxis=axis2 VREVERSE href= 21600 25200 28800 32400 36000 39600 43200 50400 54000 57600 61200 64800 68400 72000 lhref=4; format EndTime time5.; run; quit;
Thank you very much.
However, bar does not have the 'R2' pattern applied. The anno file has the 'R2' in style, but it is not applied.
Thank you very much. I sincerely appreciate the feedback.
However, bar does not have the 'R2' pattern applied. The anno file has the 'R2' in style, but it is not applied.
In this case, your 'bar' is infinitely thin, because both the bottom edge and top edge has the same yc y-coordinate ... therefore the bar has no area to plot the r1 pattern in.
You are getting what 'looks' like a bar just by luck, because you are specifying a very large size variable. The size is basically the width of the line drawn around the box ... and the line bounding the box is always drawn solid. So the solid color you're seeing is the color of the very thick line drawn around the box.
Here's one alternative way to draw/annotate the bars - rather than using the same y-value for the move/bar, use a relative coordinate system, and set the top/right corner of the bar 5% above the bottom/left y (see bold code below):
data source;
length color text $8. ;
location = 'Rm-01'; starttime='08:00't; endtime='15:30't; color = 'red'; text= 'red'; output;
location = 'Rm-02'; starttime='08:30't; endtime='16:00't; color = 'white'; text= 'white'; output;
location = 'Rm-03'; starttime='08:15't; endtime='15:15't; color = 'blue'; text= 'blue';output;
run;
data anno;
length style $5 color $12 function $12;
set source;
xsys='2'; ysys='2'; hsys='3';
style='solid';
if color='white' then do; style='r1'; color='gray99'; end;
function='move'; x=StartTime; ysys='2'; yc=location; output;
function='bar'; x=EndTime; ysys='b'; y=5; line=0; output;
function='label'; color='grau77'; size=4.0; style='Arial'; ysys='2'; position ='c';
x=StartTime ; yc=location; output;
run;
symbol1 i=none;
axis1 label=none offset=(1,4);
axis2 order=(21600 to 72000 by 3600) minor=none label=(h=1.5 "Time of Day") Value=(h=1);
proc gplot data=source annotate=anno;
plot location*EndTime/vaxis=axis1 haxis=axis2 VREVERSE
href= 21600 25200 28800 32400 36000 39600 43200
50400 54000 57600 61200 64800 68400 72000
lhref=4;
format EndTime time5.;
run;
Bob,
This was exactly what I was looking to do.
The insights are: I was manipulating the line, not the bar and that I need to use a relative coordinate system, as opposed to size, to control width.
Thank you so much.
Best Regards,
Stan
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.