Graphics Programming

Data visualization using SAS programming, including ODS Graphics and SAS/GRAPH. Charts, plots, maps, and more!
BookmarkSubscribeRSS Feed
Miah
Obsidian | Level 7

I am trying to label the point in the scatter plot with the smallest carbohydrate content, but so far I just have entered some text in the bottom left of the graph. 

 

Here it is my code and the data set: 

 

DATA work.cereal;
INFILE "/folders/myfolders/cereal.txt"
DLM=',' FIRSTOBS=2 DSD MISSOVER;
INPUT Name :$50. Manufacturer $ Type $ Calories Protein Sodium Fiber Carbohydrates Sugars Potassium Vitamins Weight Cups;
RUN;

PROC PRINT DATA=work.cereal;
RUN;

ODS GRAPHICS ON;

PROC SGPLOT DATA=cereal;
SCATTER X=Sugars Y=Carbohydrates;
XAXIS GRID VALUES=(0 TO 15 BY 3);
YAXIS GRID;
INSET 'Quaker Oatmeal' / POSITION= BOTTOMLEFT;
TITLE 'Sugars vs Carbohydrates of Cereals';
RUN;
2 REPLIES 2
Reeza
Super User

I prefer using the TEXT or MARKERCHAR statements.

 

Here's a quick example, it labels the oldest kid in the SASHELP.CLASS data set.

 

proc sort data=sashelp.class out=class; by descending age;
run;

data class_text;
set class;

if _n_=1 then text_value = "Oldest Kid";
run;

proc sgplot data=class_text;
scatter x=weight y=height;
text x=weight y=height text=text_value;
run;
ballardw
Super User

 

One way would be create an annotate data set with the location variables and appropriate instructions to display and reference that set using the SGANNO= option on the Proc statement.

 

The SCATTER statement supports providing a value label to markers using the DATALABEL option. If you use DATALABEL=variablename it will use the value of the variable to label the marker.

 

So another way would be to determine that value and then add a variable that has a value only for the records of interest to your plot dataset to reference in the scatter plot.

 

So what do you want the label to be? The numeric value of the point? The value of a different variable? if so which?

 

 

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

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
  • 2 replies
  • 4105 views
  • 1 like
  • 3 in conversation