Data visualization with SAS programming

proc sgplot

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 10
Accepted Solution

proc sgplot

[ Edited ]

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;

 

 

 

SGPlot.jpg

 

 


Accepted Solutions
Solution
3 weeks ago
Occasional Contributor
Posts: 10

Re: proc sgplot

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.

 

 

View solution in original post


All Replies
Super User
Super User
Posts: 9,211

Re: proc sgplot

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:

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

i suspect the group= part.

Occasional Contributor
Posts: 10

Re: proc sgplot

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

;;;;

 

Super User
Super User
Posts: 9,211

Re: proc sgplot

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.

Occasional Contributor
Posts: 10

Re: proc sgplot

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

;;;;

 

Super User
Super User
Posts: 9,211

Re: proc sgplot

"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.

 

Solution
3 weeks ago
Occasional Contributor
Posts: 10

Re: proc sgplot

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.

 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 103 views
  • 0 likes
  • 2 in conversation