I want to make a graph depicting the association of age with variable Y for males and females using a spline function (see code below). However, when I try to use SGPLOT to make the graph with dashed 95% clm SAS adds lines to the graph that I did not request (see Figure below). Does anyone know how to suppress these extra lines so that only the spline curve with 95% clm is visible?
Thanks,
Anders
proc orthoreg data=data;
class female;
effect spl=spline(age / naturalcubic details);
model y = spl|female / noint;
effectplot / noobs clm;
test spl|female;
store spline;
run;
proc plm source=spline;
score data=data out=pred predicted=p lclm=lower uclm=upper;
run;
proc sgplot data=pred NOAUTOLEGEND Noborder;
series y=p x=age / group=female LINEATTRS=(THICKNESS=1) name="Female";
series y=lower x=age / group=female LINEATTRS=(pattern=shortdash color=Black THICKNESS=1);
series y=upper x=age / group=female LINEATTRS=(pattern=shortdash color=Black THICKNESS=1);
keylegend "Female" / title="Female";
yaxis Label="Y" Type=Linear LABELATTRS=(weight=BOLD style=normal size=11);
xaxis Label="Age" LABELATTRS=(weight=BOLD style=normal size=11);
run;
No that is not the problem. I searched the web some more and found that the problem is that proc sgplot requires the data to be sorted by female and age before plotting. Thanks anyway.
Post some example data from the dataset created by:
proc plm source=spline; score data=data out=pred predicted=p lclm=lower uclm=upper; run;
You can use this post to help:
i suspect the group= part.
data WORK.TTR_PRED;
infile datalines dsd truncover;
input female:32. p:32. lower:32. upper:32. age_years:32.;
datalines4;
0,0.3222241319,0.3188327688,0.325615495,40
0,0.322588596,0.3194323886,0.3257448035,41
0,0.3222241319,0.3188327688,0.325615495,40
0,0.322588596,0.3194323886,0.3257448035,41
0,0.322588596,0.3194323886,0.3257448035,41
;;;;
That doesn't help as it only shows a tiny fraction. The legend is showing female variable as being either 0 or 1, hence why two sets of lines are present. The test data presented only has 0 presented. Also the X axis goes up to 80 or more, so this isn;t the complete data. If you only want one set of lines, then drop female=1 or female=0 so you only have one group of data.
Sorry. Thought you only wanted an example of the data. There are 10.000+ observations so it is not convenient to list all here. I copied the first 100 observations below. Also, just to make sure we are talking about the same thing. My question is how to get rid of the extra lines that SAS adds to the graph (see picture in my original post). I want 2 lines corresponding to the spline estimates (solid lines) for each sex with upper and lower 95% clm (dashed lines).
data WORK.DATA;
infile datalines dsd truncover;
input age:32. female:32. p:32. lower:32. upper:32.;
datalines4;
40,0,0.3222241319,0.3188327688,0.325615495
41,0,0.322588596,0.3194323886,0.3257448035
40,0,0.3222241319,0.3188327688,0.325615495
41,0,0.322588596,0.3194323886,0.3257448035
41,0,0.322588596,0.3194323886,0.3257448035
40,0,0.3222241319,0.3188327688,0.325615495
41,0,0.322588596,0.3194323886,0.3257448035
41,0,0.322588596,0.3194323886,0.3257448035
40,0,0.3222241319,0.3188327688,0.325615495
40,0,0.3222241319,0.3188327688,0.325615495
41,0,0.322588596,0.3194323886,0.3257448035
41,0,0.322588596,0.3194323886,0.3257448035
40,0,0.3222241319,0.3188327688,0.325615495
41,0,0.322588596,0.3194323886,0.3257448035
41,0,0.322588596,0.3194323886,0.3257448035
40,0,0.3222241319,0.3188327688,0.325615495
40,0,0.3222241319,0.3188327688,0.325615495
40,0,0.3222241319,0.3188327688,0.325615495
41,0,0.322588596,0.3194323886,0.3257448035
41,0,0.322588596,0.3194323886,0.3257448035
40,0,0.3222241319,0.3188327688,0.325615495
40,0,0.3222241319,0.3188327688,0.325615495
41,0,0.322588596,0.3194323886,0.3257448035
40,0,0.3222241319,0.3188327688,0.325615495
41,0,0.322588596,0.3194323886,0.3257448035
41,0,0.322588596,0.3194323886,0.3257448035
40,0,0.3222241319,0.3188327688,0.325615495
41,0,0.322588596,0.3194323886,0.3257448035
40,0,0.3222241319,0.3188327688,0.325615495
40,0,0.3222241319,0.3188327688,0.325615495
40,0,0.3222241319,0.3188327688,0.325615495
41,0,0.322588596,0.3194323886,0.3257448035
40,0,0.3222241319,0.3188327688,0.325615495
41,0,0.322588596,0.3194323886,0.3257448035
40,0,0.3222241319,0.3188327688,0.325615495
41,0,0.322588596,0.3194323886,0.3257448035
41,0,0.322588596,0.3194323886,0.3257448035
41,0,0.322588596,0.3194323886,0.3257448035
41,0,0.322588596,0.3194323886,0.3257448035
41,0,0.322588596,0.3194323886,0.3257448035
41,0,0.322588596,0.3194323886,0.3257448035
29,0,0.3178219885,0.31102658,0.3246173969
41,0,0.322588596,0.3194323886,0.3257448035
40,0,0.3222241319,0.3188327688,0.325615495
41,0,0.322588596,0.3194323886,0.3257448035
41,0,0.322588596,0.3194323886,0.3257448035
40,0,0.3222241319,0.3188327688,0.325615495
41,0,0.322588596,0.3194323886,0.3257448035
40,0,0.3222241319,0.3188327688,0.325615495
40,0,0.3222241319,0.3188327688,0.325615495
40,0,0.3222241319,0.3188327688,0.325615495
41,0,0.322588596,0.3194323886,0.3257448035
40,0,0.3222241319,0.3188327688,0.325615495
41,0,0.322588596,0.3194323886,0.3257448035
41,0,0.322588596,0.3194323886,0.3257448035
41,0,0.322588596,0.3194323886,0.3257448035
40,0,0.3222241319,0.3188327688,0.325615495
40,0,0.3222241319,0.3188327688,0.325615495
40,0,0.3222241319,0.3188327688,0.325615495
41,0,0.322588596,0.3194323886,0.3257448035
40,0,0.3222241319,0.3188327688,0.325615495
40,0,0.3222241319,0.3188327688,0.325615495
41,0,0.322588596,0.3194323886,0.3257448035
32,0,0.3190284679,0.3132385942,0.3248183416
32,0,0.3190284679,0.3132385942,0.3248183416
38,0,0.3214412539,0.3175171465,0.3253653613
32,0,0.3190284679,0.3132385942,0.3248183416
41,0,0.322588596,0.3194323886,0.3257448035
31,0,0.3186263081,0.3125046405,0.3247479757
40,0,0.3222241319,0.3188327688,0.325615495
33,0,0.3194306277,0.3139683391,0.3248929164
26,0,0.3166155091,0.3087906933,0.3244403248
41,0,0.322588596,0.3194323886,0.3257448035
40,0,0.3222241319,0.3188327688,0.325615495
38,0,0.3214412539,0.3175171465,0.3253653613
39,0,0.3218389179,0.3181901864,0.3254876493
41,0,0.322588596,0.3194323886,0.3257448035
41,0,0.322588596,0.3194323886,0.3257448035
22,0,0.3150068698,0.3057862116,0.324227528
33,0,0.3194306277,0.3139683391,0.3248929164
40,0,0.3222241319,0.3188327688,0.325615495
41,0,0.322588596,0.3194323886,0.3257448035
40,0,0.3222241319,0.3188327688,0.325615495
31,0,0.3186263081,0.3125046405,0.3247479757
41,0,0.322588596,0.3194323886,0.3257448035
41,0,0.322588596,0.3194323886,0.3257448035
39,0,0.3218389179,0.3181901864,0.3254876493
41,0,0.322588596,0.3194323886,0.3257448035
40,0,0.3222241319,0.3188327688,0.325615495
38,0,0.3214412539,0.3175171465,0.3253653613
40,0,0.3222241319,0.3188327688,0.325615495
41,0,0.322588596,0.3194323886,0.3257448035
27,0,0.3170176689,0.3095380376,0.3244973001
41,0,0.322588596,0.3194323886,0.3257448035
39,0,0.3218389179,0.3181901864,0.3254876493
41,0,0.322588596,0.3194323886,0.3257448035
41,0,0.322588596,0.3194323886,0.3257448035
27,0,0.3170176689,0.3095380376,0.3244973001
23,0,0.3154090296,0.3065392419,0.3242788174
41,0,0.322588596,0.3194323886,0.3257448035
;;;;
"My question is how to get rid of the extra lines that SAS adds to the graph (see picture in my original post)." - no sorry, not clear to me. The graph is plotting all 10,000 lines based on a grouping a female variable. As there is very little difference between each result its very hard to see any difference, but it is like ploting row 1, then row 2 etc.
Perhaps you mean to summarise the data before you plot? Maybe it should be the mean p, lower, upper grouped by female and age, then plot the output of that:
proc means data=have; by female age; var p lower upper; output out=want autolabel; run; proc sgplot data=want noautolegend noborder; series y=p_mean x=age / group=female lineattrs=(thickness=1) name="Female"; series y=lower_mean x=age / group=female lineattrs=(pattern=shortdash color=Black thickness=1); series y=upper_mean x=age / group=female lineattrs=(pattern=shortdash color=Black thickness=1); keylegend "Female" / title="Female"; yaxis Label="Y" Type=Linear labelattrs=(weight=boldstyle=normal size=11); xaxis Label="Age" labelattrs=(weight=bold style=normal size=11); run;
This should create a dataset want with a row for each age within each female, so just a few rows. This then gets plotted.
No that is not the problem. I searched the web some more and found that the problem is that proc sgplot requires the data to be sorted by female and age before plotting. Thanks anyway.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.