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 is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
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: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 3 replies
  • 767 views
  • 1 like
  • 3 in conversation