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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
GraphGuy
Meteorite | Level 14

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;

 

bar.png

View solution in original post

9 REPLIES 9
pink_poodle
Barite | Level 11

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

SSTEAD
Obsidian | Level 7

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:

barcolor text location starttime endtime
red red Rm-01 28800 15:30
white white Rm-02 30600 16:00
blue blue Rm-03 29700 15:15

**** Here is anno ****

style function xsys ysys size barcolor text location starttime endtime line color X yc
Empty MOVE 2 2 44 red red Rm-01 28800 55800 0 red 28800 Rm-01
R5 BAR 2 2 44 red red Rm-01 28800 55800 0 red 55800 Rm-01
Empty MOVE 2 2 44 white white Rm-02 30600 57600 0 white 30600 Rm-02
R5 BAR 2 2 44 white white Rm-02 30600 57600 0 white 57600 Rm-02
Empty MOVE 2 2 44 blue blue Rm-03 29700 54900 0 blue 29700 Rm-03
R5 BAR 2 2 44 blue blue Rm-03 29700 54900 0 blue 54900 Rm-03

 

Here is the output

gplot.png

 

ballardw
Super User

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;

 

 

 

SSTEAD
Obsidian | Level 7

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. 

 

style color function xsys ysys size BlkHldrLabel text location starttime endtime line x yc position
solidredmove2244redRm-012880055800128800Rm-01
solidredbar2244redRm-012880055800155800Rm-01
Arial Black white label 2 2 3 red Rm-01 28800 55800 1 28800 Rm-01 6
R2light greymove223whiteRm-023060057600130600Rm-02
R2light greybar2244whiteRm-023060057600157600Rm-02
Arial Black white label 2 2 3 white Rm-02 30600 57600 1 30600 Rm-02 6
solidbluemove223blueRm-032970054900129700Rm-03
solidbluebar2244blueRm-032970054900154900Rm-03
Arial Black white label 2 2 3 blue Rm-03 29700 54900 1 29700 Rm-03 6
 

 

SSTEAD
Obsidian | Level 7

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. 

 

screenshot_130.png

pink_poodle
Barite | Level 11
Does R2 show up if you comment out this function statement?:
/* function='label' ; color='white'; size=3 ; style='Arial Black'; position ='6' ;
x=StartTime ; yc=location; output; */
GraphGuy
Meteorite | Level 14

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.

 

GraphGuy
Meteorite | Level 14

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;

 

bar.png

SSTEAD
Obsidian | Level 7

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

 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 9 replies
  • 1313 views
  • 2 likes
  • 4 in conversation