Doing a adverse event plot were I have to put some stat numbers together with a scatter plot (see below). Now I want the stat numbers to be right aligned with the tickmark at the x axis (see red inserted line).
proc template; define statgraph demo; begingraph ; layout overlay; scatterplot y=name x=w / markercharacter =weightc MARKERCHARACTERPOSITION=left xaxis=x2; scatterplot y=name x=h / markercharacter =height MARKERCHARACTERPOSITION=left xaxis=x2; endlayout; endgraph; end; run; data class2; set sashelp.class; weightc=put(weight,4.1); heightc=put(height,4.1); w="kg"; h="cm"; run; proc sgrender data=class2 template=demo; run;
Have created a little sandbox example using the good old sashelp.class :-). Any ideas on how to solve this?
I see at least two issues.
First I think you have the wrong variable for the markercharacter in the second scatter plot statement.
Second, if you expect the formatted value to have a decimal for everything you need to provide a wide enough format.
Using 4.1 with values like 112.5 for example, Alfred's weight you do not have enough space to display 112.5 you would need a 5.1. Otherwise the width specification of 4 means 112. uses all the positions. And if there is no value to right of the decimal then SAS doesn't display the decimal.
So see if this gets closer to what you expect:
proc template; define statgraph demo; begingraph ; layout overlay; scatterplot y=name x=w / markercharacter =weightc MARKERCHARACTERPOSITION=left xaxis=x2; scatterplot y=name x=h / markercharacter =heightc MARKERCHARACTERPOSITION=left xaxis=x2; endlayout; endgraph; end; run; data class2; set sashelp.class; weightc=put(weight,5.1); heightc=put(height,4.1); w="kg"; h="cm"; run; proc sgrender data=class2 template=demo; run;
Thanks for your input. However the issue is the right alignment of the tickmark with the height and weight data. A solution could be to insert trailering blanks on the "kg" and "cm" but they just seem to be cut off when displaying.....Another solution could be to go with the axais table as Matange suggesst below.
You will get better results using AxisTable for displaying the numbers. This can be done using SGPLOT with YAXISTABLE. YAXISTABLE has many options for positioning of the text. You can also use AXISTABLE in GTL.
See the last example.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.