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 2025: Call for Content

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!

Submit your idea!

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