Hi All, Sorry if it's already post, can't see the first 2 posts idid.
Can You please help to find out what’s wrong with my code, I’m trying to have spaghetti plot for 2 groups (TRTN), I want to control the color, the thickness, and symbols etc…by treatment. i.e all subjects within the same group have same color etc. The line plot are mixed up and do not display the correct values.
I want for TRT=1 RED LINE and solid.
For TRTN=2 BLUE LINE AND SHORTDASH
proc sgplot data=my_data;
title1 'MY TITLTE';
title2;
styleattrs datacontrastcolors=(red blue)
datasymbols=(squarefilled trianglefilled)
datalinepatterns=(Solid ShortDash);
series x=avisitn y=aval / group=subjid grouplc=trtn name='grouping' Markers MARKERATTRS = (color = black) curvelabel;
scatter x=avisitn y=aval / group = subjid name = 'subjid' markerattrs=(color = black );
xaxis display=all grid integer values=(12 13 14 15 16 17) valueshint;
yaxis LABEL = 'YLABEL)' grid;
keylegend 'grouping' / type=linecolor;
run;
Here is my data
data my_data ;
input subjid avisit $ avisitn aval trt $ trtn;
datalines;
20110100 Month3 14 2.9 A 1
20110101 Baseline 13 2.3 A 1
20110101 Month3 14 2 A 1
20110101 Month6 15 2.3 A 1
20110101 Month9 16 2.9 A 1
20110200 Baseline 13 2.7 A 1
20110200 Baseline 13 2.9 A 1
20110200 Month3 14 2 A 1
20110200 Month6 15 2 A 1
20110200 Month9 16 2 A 1
20110200 Month12 17 1.4 A 1
20110300 Baseline 13 2 A 1
20110300 Month3 14 1.8 A 1
20110300 Month6 15 2 A 1
20110600 Month3 14 2.9 A 1
20110200 Baseline 13 2.3 B 2
20110200 Baseline 13 2.3 B 2
20110200 Month3 14 2.7 B 2
20110200 Month6 15 2.3 B 2
20110200 Month9 16 2.5 B 2
20110200 Month12 17 2.3 B 2
20110600 Month3 14 2.9 B 2
;
run;
You need change your data structure.
Ksharp:
data my_data ;
input subjid avisitn aval trtn;
datalines;
1 1 1.2 1
1 2 1.4 1
1 3 1.6 1
1 4 1.8 1
2 1 2.2 1
2 2 2.4 1
2 3 2.6 1
2 4 2.8 1
3 1 3.2 2
3 2 3.4 2
3 3 3.6 2
3 4 3.8 2
4 1 4.2 2
4 2 4.4 2
4 3 4.6 2
4 4 4.8 2
;
proc sort data=my_data out=temp;
by trtn subjid avisitn;
run;
data temp2;
merge temp(where=(trtn=1))
temp(where=(_trtn=2) rename=(subjid=_subjid avisitn=_avisitn aval=_aval trtn=_trtn)) ;
output;
call missing(of _all_);
run;
proc sgplot data=temp2 noautolegend;
series x=avisitn y=aval / group=subjid lineattrs=(color=yellowgreen thickness=4 pattern=Solid )
markers markerattrs=(symbol=squarefilled size=12) ;
series x=_avisitn y=_aval / group=subjid lineattrs=(color=red thickness=2 pattern=ShortDash )
markers markerattrs=(symbol=trianglefilled size=8) ;
run;
You need change your data structure.
Ksharp:
data my_data ;
input subjid avisitn aval trtn;
datalines;
1 1 1.2 1
1 2 1.4 1
1 3 1.6 1
1 4 1.8 1
2 1 2.2 1
2 2 2.4 1
2 3 2.6 1
2 4 2.8 1
3 1 3.2 2
3 2 3.4 2
3 3 3.6 2
3 4 3.8 2
4 1 4.2 2
4 2 4.4 2
4 3 4.6 2
4 4 4.8 2
;
proc sort data=my_data out=temp;
by trtn subjid avisitn;
run;
data temp2;
merge temp(where=(trtn=1))
temp(where=(_trtn=2) rename=(subjid=_subjid avisitn=_avisitn aval=_aval trtn=_trtn)) ;
output;
call missing(of _all_);
run;
proc sgplot data=temp2 noautolegend;
series x=avisitn y=aval / group=subjid lineattrs=(color=yellowgreen thickness=4 pattern=Solid )
markers markerattrs=(symbol=squarefilled size=12) ;
series x=_avisitn y=_aval / group=subjid lineattrs=(color=red thickness=2 pattern=ShortDash )
markers markerattrs=(symbol=trianglefilled size=8) ;
run;
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!
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.