Back in February, I posted an article on creating Adverse Event Timeline Graph. In the SAS 9.2 version (first one), one item that was less than ideal was the way to position the AE names to the left of the event. The AE names are displayed using the scatter plot statement with the markerchar option. The string is displayed center justified at the (x, y) location for the scatter marker.
If the left end of the event is provided as the (x, y) location, the center of the label is placed there, with half the label to the left, and half to the right. The only way I could shift the label fully to the left is to compute a new x location that was offset to the left by half the character string. The character string is in pixels, and with proportional fonts one has to estimate the value of x in "date" coordinates not knowing exactly how much of the graph width is actually used for the x axis, so some approximation is inevitable.
Furthermore, when this method was used by some readers for their own data, the math did not always work out if the coordinates became negative (it did not happen for my use case, so I did not test that use case).
As mentioned in the same article above, SAS 9.3 makes it much easier to create the same graph using the new HighLow plot. But, if you must use SAS 9.2 to create this graph, here is some good news. Over the past few weeks, I have been experimenting with the use of non-breaking space, and have come up with an alternate way to solve this case more elegantly using the nbsp.
The new method avoids computing an approximate new x location for the center of the label all together. So we get away from all that kludgy code. The key to the method is as follows:
- Create a label string twice as long as the original one filled with blanks.
- Stuff the name in the left half of the string, leaving the right half empty.
- Replace all blanks with non-breaking blanks (so they will be retained).
- Use a non-proportional font to draw the names.
- Draw the string at the exact left end of the event (StartDay).
- Presto - the event name is drawn just to the left of the event start.
Here is the new graph:
Here is the full SAS 9.2 code: Full SAS Code_92