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;
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;
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?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.