<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How do I make a spaghetti plot with this data? in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-do-I-make-a-spaghetti-plot-with-this-data/m-p/942632#M45195</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input subject Baseline month1;
cards;
23 4 4
26 3 0
36 3 0
39 4 1
41 4 3
42 0 3
46 0 1
49 1 0
51 0 0
55 2 4
56 2 1
57 4 1
73 2 0
83 2 0
84 1 1
85 3 2
89 0 0
96 2 0
101 2 3
112 2 0
117 4 0
120 2 1
124 2 0
;
run;

data scatter;
do x3=0.5 ,2.5;
 do y3=0.5 to 4.5 by 0.5;
   output;
 end;
end;
run;

proc transpose data= have out=canplot prefix=y;
   by subject;
run;
proc sql;
create table want as
select *,ifn(_NAME_='Baseline',1,2) as g from canplot
outer union 
select 1 as x2,median(Baseline) as y2 from have   /*Baseline*/
outer union corr
select 2 as x2,median(month1) as y2 from have  /*month1*/
outer union 
select * from scatter
;quit;

title 'Change in Score';
proc sgplot data=want noautolegend noborder aspect=0.5;
styleattrs datacontrastcolors=(orange black) datalinepatterns=(solid dash);
  series x=g y=y1 / group=subject lineattrs=(color=orange thickness=8 pattern=solid) transparency=0.5;
  series x=x2 y=y2/lineattrs=(color=black thickness=8 pattern=dash);
  scatter x=x3 y=y3;
  xaxis type=linear offsetmin=0.01 values=(0.5 1 2 2.5) valuesdisplay=(' ' 'Baseline' '1 month' ' ') display=(noline noticks);
  yaxis values=(0 to 4.5 by 0.5) grid display=(noline noticks) valuesformat=best.;
  label x3='Time-Point';
  label y3='Score';
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1725503035607.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/99987i274C6F1886B44972/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1725503035607.png" alt="Ksharp_0-1725503035607.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 05 Sep 2024 02:24:07 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2024-09-05T02:24:07Z</dc:date>
    <item>
      <title>How do I make a spaghetti plot with this data?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-do-I-make-a-spaghetti-plot-with-this-data/m-p/941559#M45166</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I use SAS EG 8.3 and I have a small dataset "have" with variables subject, score at baseline, and score at month 1.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data have;
input subject Baseline month1;
cards;
23 4 4
26 3 0
36 3 0
39 4 1
41 4 3
42 0 3
46 0 1
49 1 0
51 0 0
55 2 4
56 2 1
57 4 1
73 2 0
83 2 0
84 1 1
85 3 2
89 0 0
96 2 0
101 2 3
112 2 0
117 4 0
120 2 1
124 2 0
;
run;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I produce a spaghetti plot that looks like this one attached (below)? I would also like to add a line for the median (that is the black dashed line in the attachment).&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-08-28 163300.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/99713i6F878C705ADA1260/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2024-08-28 163300.png" alt="Screenshot 2024-08-28 163300.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2024 20:47:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-do-I-make-a-spaghetti-plot-with-this-data/m-p/941559#M45166</guid>
      <dc:creator>rwe_stat</dc:creator>
      <dc:date>2024-08-28T20:47:49Z</dc:date>
    </item>
    <item>
      <title>Re: How do I make a spaghetti plot with this data?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-do-I-make-a-spaghetti-plot-with-this-data/m-p/941595#M45167</link>
      <description>&lt;P&gt;Plots will typically require an Xaxis value and Yaxis value for most types of plots. So your data needs to be shaped to match that requirement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc transpose data= have out=canplot prefix=y;
   by subject;
run;

proc sgplot data=canplot;
  series x=_name_ y=y1 / group=subject;
  label _name_='Time';&lt;BR /&gt;  label y1='Score';
run;&lt;/PRE&gt;
&lt;P&gt;With the basic plot out of the way, what do you mean by "median" in this case?&lt;/P&gt;
&lt;P&gt;You will need to calculate it and either add to the data or annotate .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2024 01:14:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-do-I-make-a-spaghetti-plot-with-this-data/m-p/941595#M45167</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-08-29T01:14:10Z</dc:date>
    </item>
    <item>
      <title>Re: How do I make a spaghetti plot with this data?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-do-I-make-a-spaghetti-plot-with-this-data/m-p/942632#M45195</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input subject Baseline month1;
cards;
23 4 4
26 3 0
36 3 0
39 4 1
41 4 3
42 0 3
46 0 1
49 1 0
51 0 0
55 2 4
56 2 1
57 4 1
73 2 0
83 2 0
84 1 1
85 3 2
89 0 0
96 2 0
101 2 3
112 2 0
117 4 0
120 2 1
124 2 0
;
run;

data scatter;
do x3=0.5 ,2.5;
 do y3=0.5 to 4.5 by 0.5;
   output;
 end;
end;
run;

proc transpose data= have out=canplot prefix=y;
   by subject;
run;
proc sql;
create table want as
select *,ifn(_NAME_='Baseline',1,2) as g from canplot
outer union 
select 1 as x2,median(Baseline) as y2 from have   /*Baseline*/
outer union corr
select 2 as x2,median(month1) as y2 from have  /*month1*/
outer union 
select * from scatter
;quit;

title 'Change in Score';
proc sgplot data=want noautolegend noborder aspect=0.5;
styleattrs datacontrastcolors=(orange black) datalinepatterns=(solid dash);
  series x=g y=y1 / group=subject lineattrs=(color=orange thickness=8 pattern=solid) transparency=0.5;
  series x=x2 y=y2/lineattrs=(color=black thickness=8 pattern=dash);
  scatter x=x3 y=y3;
  xaxis type=linear offsetmin=0.01 values=(0.5 1 2 2.5) valuesdisplay=(' ' 'Baseline' '1 month' ' ') display=(noline noticks);
  yaxis values=(0 to 4.5 by 0.5) grid display=(noline noticks) valuesformat=best.;
  label x3='Time-Point';
  label y3='Score';
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1725503035607.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/99987i274C6F1886B44972/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1725503035607.png" alt="Ksharp_0-1725503035607.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2024 02:24:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-do-I-make-a-spaghetti-plot-with-this-data/m-p/942632#M45195</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-09-05T02:24:07Z</dc:date>
    </item>
  </channel>
</rss>

