BookmarkSubscribeRSS Feed
jdmarino
Fluorite | Level 6

I'm building an overlay layout that has needle plots for trades and bandplots for cumulative positions.  The positions can grow to overshadow the trades, making the needles tiny, so I've placed trades on the yaxis and the position on the y2axis.  I'd like the zero value of the y axes to be the same, i.e. that the axes are scaled differently, but "pinned" to a common ground.  Is this possible?

6 REPLIES 6
Jay54
Meteorite | Level 14


This should be doable by setting MIN =0 on both Y and Y2 axes..  You could also set OFFSETMIN=0 for both  Y and Y2 axes to ensure the needles touch the X axis.

jdmarino
Fluorite | Level 6

Ah, but zero is in the middle: trades and positions can be positive or negative.

Jay54
Meteorite | Level 14

Aah.  Interesting.  Then I suggest set the MIN and MAX for both Y and Y2 in the same proportion.  So, if for band (on Y) the min= -100 and max= +200, then make the min and max for the needle (on Y2) in the same proportion.  So, if  the needle min= -20 and max=+20, make Y2 min= -20 and max=+40.  I believe this should set the zero at the same place for both axes.  Place a reference line for Y=0 and see how it lines up with Y2.

Synch.png

data synch;
  do x=1 to 10 by 1;
    y1=10*rannor(2);
    y2=rannor(2);
    output;
  end;
run;

proc sgplot data=synch cycleattrs;
  series x=x y=y1;
  needle x=x y=y2 / y2axis;
  refline 0;
  yaxis min=-10 max=20;
  y2axis min=-2 max=4 valueattrs=graphdata2 labelattrs=graphdata2;
run;

jdmarino
Fluorite | Level 6

Thanks.  I guess I did not overlook the built-in option for this to does it automagically.

I don't want to hard code these values, and detecting them and scaling sounds like a fair bit of effort.  I'm using proc template and I'd have to pass some dynamic or macro vars, which I find troublesome (i.e. I have trouble getting them to work).

Jay54
Meteorite | Level 14

No, automatic solution at this time.  Yes, you can use some logic to compute the min and max values in macro variables, and set on the axis.  Alternately, do you have to use overlaid plots?  Could you place each plot in its own graph, with a common x axis.  Or, use the Waterfall chart, where each observation is a transaction and the cumulative result is automatically computed.  Waterfall is available in SG, but to create a two cell graph with common X axis, you need GTL.

jdmarino
Fluorite | Level 6

Thanks again for all the help.  I don't have to use overlaid charts, and I think that's the best option.  Waterfall may work, so long as I can give it a starting base value.  (The graph actually has needles for two kinds of trading [stocks and swaps], a band for each, and a seriesplot fo the total cumulative position.  I'm not inclined to ditch it all at this point.)  It's interesting that so many chart types can be transformed to server other purposes.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 6 replies
  • 1737 views
  • 6 likes
  • 2 in conversation