BookmarkSubscribeRSS Feed
BigD
Calcite | Level 5

Hi,

I am having trouble getting  vertical lines as targets in the proper place for a hbar chart using sgplot procedure

data looks something like this

Facilityresponsetarget
h12636
h2818
h3115
h4112140

Graph should look like this or so (with the red lines being the targets)

Capture.JPG

I've seen it done with the regular annotate facility, but haven't been able to get too far with sganno

Thanks for your help.

Bruce

2 REPLIES 2
Jay54
Meteorite | Level 14

While you can certainly do this with SGAnno, you don't need annotate  You can use HBarParm and HiglLow combination to get what you need.  You can reduce the bar width if you need.  Here is the graph and the code.

TargetSG.png

data target;
  input Facility $ Response Target;
  datalines;
H1  26  36
H2   8  18
H3  11  25
H4 112 140
;
run;


title 'Response and Target by Facility';
proc sgplot data=target;
  hbarparm category=facility response=response / fillattrs=graphdata1 name='a';
  highlow  y=facility low=target high=target / lineattrs=graphdata2(thickness=2 pattern=solid)
    name='t' legendlabel='Target';
  highlow  y=facility low=target high=target / type=bar lineattrs=graphdata2(thickness=2 pattern=solid);
  xaxis display=(nolabel) offsetmin=0;
  yaxis display=(nolabel) reverse;
  discretelegend 'a' 't';
  run;

Two HighLow plots are used.  One with default Type=Line for the legend.  The other with Type=bar for the actual target in the graph.  You could use a scatter plot to draw the target for a different look.

TargetSG2.png

title 'Response and Target by Facility';

proc sgplot data=target;

  hbarparm category=facility response=response / fillattrs=graphdata1 name='a';

  scatter  y=facility x=target / markerattrs=graphdata2(symbol=triangledownfilled size=11)

    name='t' legendlabel='Target' discreteoffset=0.3;

  xaxis display=(nolabel) offsetmin=0;

  yaxis display=(nolabel) reverse;

  discretelegend 'a' 't';

  run;

BigD
Calcite | Level 5

Thanks so much. Much easier and serves my purpose well.

Still would like to see the sganno solution as it would come in handy.

Bruce

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1818 views
  • 3 likes
  • 2 in conversation