BookmarkSubscribeRSS Feed
Claus_Stenberg
Fluorite | Level 6

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;

example.png

 

Have created a little sandbox example using the good old sashelp.class :-). Any ideas on how to solve this? 

4 REPLIES 4
ballardw
Super User

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;
Claus_Stenberg
Fluorite | Level 6

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.  

 

 

Claus_Stenberg_0-1618814576668.png

 

 

Jay54
Meteorite | Level 14

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:

https://blogs.sas.com/content/graphicallyspeaking/2016/05/06/ctspedia-graphs-dot-plot-of-primary-soc...

 

https://blogs.sas.com/content/iml/2019/09/11/axis-tables-rotated-text.html

See the last example.

 

 

Claus_Stenberg
Fluorite | Level 6

Thanks for your suggestion about the AXISTABLE solution.  Was down that road initially but then used the scatterplot option as it was easier to make dynamic. Will revert and try this once more 🙂

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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