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

BASUG is hosting free webinars Next up: Mark Keintz presenting History Carried Forward, Future Carried Back: Mixing Time Series of Differing Frequencies on May 8. Register now at the Boston Area SAS Users Group event page: 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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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