BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
jojo
Obsidian | Level 7

I am working on spaghetti plot using proc sgplot, just wonder if there is a way to add the data value on each data point. 

1 ACCEPTED SOLUTION

Accepted Solutions
LeliaM
SAS Employee

You can add a label at each data point on a spaghetti plot, with the DATALABEL option after the / on the SERIES statement.  Below is sample code that illustrates the syntax:

data one;
input trt_group time subject results;
datalines;
1 2 100 20
1 4 100 30
1 6 100 35
1 8 100 50
1 2 200 40
1 4 200 25
1 6 200 40
1 8 200 30
1 2 300 25
1 4 300 40
1 6 300 45
1 8 300 55
2 2 400 15
2 4 400 35
2 6 400 50
2 8 400 45
2 2 500 35
2 4 500 35
2 6 500 20
2 8 500 35
;
run;
ODS html;
proc sgplot data=one;
title 'Study Results by Treatment Group';
series x=time y=results / group=subject grouplc=trt_group name='grouping' datalabel=results;
keylegend 'grouping' / type=linecolor;
run;

View solution in original post

3 REPLIES 3
Quentin
Super User

Can you please show a small example of your data, and your code to produce the spaghetti plot without the labels?  And then describe what data value labels you want to add.  Normally a spaghetti plot will be a lot of overlapping lines (like spaghetti), so labeling values wouldn't make sense.  Do you mean you want to label each strand of the spaghetti?

 

This blog post by Rick Wicklin might be helpful to you.  It shows a spaghetti plot, and discusses how spaghetti plots differ from line plots.  https://blogs.sas.com/content/iml/2016/06/02/create-spaghetti-plots-in-sas.html

The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.
LeliaM
SAS Employee

You can add a label at each data point on a spaghetti plot, with the DATALABEL option after the / on the SERIES statement.  Below is sample code that illustrates the syntax:

data one;
input trt_group time subject results;
datalines;
1 2 100 20
1 4 100 30
1 6 100 35
1 8 100 50
1 2 200 40
1 4 200 25
1 6 200 40
1 8 200 30
1 2 300 25
1 4 300 40
1 6 300 45
1 8 300 55
2 2 400 15
2 4 400 35
2 6 400 50
2 8 400 45
2 2 500 35
2 4 500 35
2 6 500 20
2 8 500 35
;
run;
ODS html;
proc sgplot data=one;
title 'Study Results by Treatment Group';
series x=time y=results / group=subject grouplc=trt_group name='grouping' datalabel=results;
keylegend 'grouping' / type=linecolor;
run;

jojo
Obsidian | Level 7

Thanks very much!

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