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 🙂

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 593 views
  • 2 likes
  • 3 in conversation