BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Crowasaurus
Calcite | Level 5

I am trying to plot two regression curves with 95% CIs in separate rows by specifying a lattice layout. The issue I am having is that I am getting extra diagonal lines. I think the problem is potentially similar to a question posted by user ammarhm titled: 'strange behaviour of proc lifetest with strata'. However, I am no programmer, and this is my first time delving into GTL language. I am using SAS v 9.04.01M7P080520. The sample dataset I am using is below:

 

data WORK.WANT3;
infile datalines dsd truncover;
input year:BEST12. early_onset:32. new_rate:32. upper_limit:32. lower_limit:32.;
format year BEST12.;
datalines;
1995 0 0.0043981047 0.0044372753 0.0043592798
1995 1 0.0002554513 0.0002593269 0.0002516337
1996 0 0.0042431229 0.0042786876 0.0042078538
1996 1 0.0002464496 0.0002501219 0.0002428313
1997 0 0.0040936025 0.0041258304 0.0040616262
1997 1 0.0002377652 0.000241249 0.0002343317
1998 0 0.0039493508 0.0039785069 0.0039204085
1998 1 0.0002293867 0.0002326962 0.0002261244
1999 0 0.0038101824 0.0038365289 0.0037840168
1999 1 0.0002213035 0.000224452 0.0002181993
2000 0 0.003675918 0.0036997174 0.0036522718
2000 1 0.0002135052 0.0002165053 0.0002105466
2001 0 0.0035463849 0.0035679017 0.0035249979
2001 1 0.0002059816 0.0002088454 0.0002031571
2002 0 0.0034214163 0.0034409194 0.0034020238
2002 1 0.0001987232 0.000201462 0.0001960216
2003 0 0.0033008514 0.0033186155 0.0032831824
2003 1 0.0001917205 0.0001943449 0.0001891316
2004 0 0.003184535 0.0032008409 0.0031683122
2004 1 0.0001849646 0.0001874845 0.0001824785
2005 0 0.0030723174 0.0030874495 0.0030572594
2005 1 0.0001784468 0.0001808715 0.0001760545
2006 0 0.0029640541 0.0029782953 0.0029498811
2006 1 0.0001721586 0.0001744968 0.0001698517
2007 0 0.0028596059 0.0028732286 0.0028460478
2007 1 0.000166092 0.0001683516 0.0001638628
2008 0 0.0027588382 0.0027720945 0.0027456454
2008 1 0.0001602392 0.0001624275 0.0001580805
2009 0 0.0026616214 0.0026747329 0.0026485743
2009 1 0.0001545927 0.0001567162 0.0001524979
2010 0 0.0025678304 0.0025809815 0.0025547464
2010 1 0.0001491451 0.00015121 0.0001471083
2011 0 0.0024773444 0.0024906803 0.00246408
2011 1 0.0001438895 0.0001459013 0.0001419054
2012 0 0.002390047 0.002403675 0.0023764963
2012 1 0.000138819 0.0001407826 0.0001368828
2013 0 0.0023058258 0.0023198202 0.0022919158
2013 1 0.0001339273 0.000135847 0.0001320347
2014 0 0.0022245724 0.0022389798 0.0022102577
2014 1 0.0001292079 0.0001310877 0.0001273551
2015 0 0.0021461822 0.0021610274 0.0021314391
2015 1 0.0001246549 0.0001264981 0.0001228385
2016 0 0.0020705544 0.0020858452 0.0020553758
2016 1 0.0001202622 0.0001220718 0.0001184794
2017 0 0.0019975916 0.0020133231 0.001981983
2017 1 0.0001160244 0.000117803 0.0001142726
2018 0 0.0019271999 0.001943358 0.001911176
2018 1 0.0001119359 0.0001136858 0.0001102129
;;;;

 

Running the following code:

 

proc sort data = want3; by year early_onset; run;
proc template;
   define style Styles.MyGrids;
      parent=styles.statistical;
      class GraphGridLines /
         displayopts = "on"
         linethickness = 1px
         linestyle = 1
         contrastcolor = GraphColors('ggrid')
         color = GraphColors('ggrid'); class GraphData1 /
          contrastcolor=blue linestyle=1;
    class GraphData2 /
          contrastcolor=RED linestyle=1;
   end;
run;



proc template;
 define statgraph test;
 begingraph / AXISLINEEXTENT=DATA;
 layout lattice / rows=2 rowweights=(.7 .3) rowgutter=5;
 SIDEBAR / align=bottom;
     discretelegend "Early" "Late";
ENDSIDEBAR;
         layout Overlay / walldisplay=none
		xaxisopts= (display=none linearopts=(viewmin=1995 viewmax=2018
tickvaluesequence=(start=1995 end=2018 increment=5)) griddisplay=on)
                       yaxisopts=(display=(ticks tickvalues) griddisplay=on
                                  linearopts=(viewmin=0.0015 viewmax=0.005 tickvaluesequence=(start=0.0015 end=0.005
increment=0.001)) label=" ");
bandplot x=year limitupper=upper_limit
          limitlower=lower_limit/

name="band" modelname="want3"
legendlabel="Late Onset" name="Late";
seriesplot x=year y=new_rate/ curvelabel="Late" primary=true
lineattrs=GraphData1;
endlayout;
layout overlay / walldisplay=none
xaxisopts=(display=(ticks tickvalues) linearopts=(viewmin=1995 viewmax=2018 tickvaluesequence=(start=1995
end=2018 increment=5)) griddisplay=on)
                       yaxisopts=(display=(ticks tickvalues) griddisplay=on
                                  linearopts=(viewmin=0 viewmax=0.0005 tickvaluesequence=(start=0 end=0.0005
increment=0.00025)) label=" ");
bandplot x=year limitupper=upper_limit

          limitlower=lower_limit/
          fillattrs=(color=red)
		  outlineattrs=(color=red)
name="band" modelname="want3"
          legendlabel="Early Onset" name="Early";
   seriesplot x=year y=new_rate / curvelabel="Early" primary=true
lineattrs=GraphData2;    
endlayout;
endlayout;
endgraph;
end;
run;
								  
ods graphics on/ attrpriority=none;
ods listing gpath="Downloads";
ods listing style=MyGrids;
proc sgrender data=want3 template=test;
 run;
 ods graphics off;
ods _all_ close;

I get the resulting ugly plot SGRender39.png

 

Weirdly, if I run the sgplot procedure, the resulting plot looks fine. The reason I want to use the v.9.4 GTL language is that I want to control the proportion of space occupied by each plot.

 

SGPLOT Code: 

ods graphics on/ attrpriority=none;
ods listing gpath="Downloads";
ods listing style=mygrids;
proc sgplot data=want3;
styleattrs datalinepatterns=(solid) axisbreak=spark axisextent=data ;
legenditem type=markerline name="0" /
      label="Late" lineattrs=GraphData1 markerattrs=GraphData1;
legenditem type=markerline name="1" /
      label="Early" lineattrs=GraphData2 markerattrs=GraphData2;
keylegend "0" "1"/ title="Onset";
band x=Year lower=Lower_Limit upper=Upper_Limit / group=Early_Onset transparency=0.75;
   series x=Year y=new_rate / group=Early_onset curvelabel;
yaxis ranges=(min-0.0005 0.0015-max) values=(0 to 0.0005 by 0.0005 0.0015 to 0.005 by 0.001) valueshint;
 run;
ods _all_ close;

Any help would be greatly appreciated!

 

Gratefully,

Crow

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

The reason it is working for PROC SGPLOT is because you are using the GROUP=Early_Onset option. which tells the graph to draw separate curves for each level of the Early_Onset variable.

In the GTL, you are not using that option. Instead you are using two SERIESPLOT statements and two BANDPLOT statements. But the template will render all observations, which is why the curve jumps from the upper to the lower curve.

 

The easiest solution is to rewrite the GTL to use a GROUP variable. The (more complicated) solution is to reshape the data from long to wide format. If you do that, you will need the variables (year1, upper1, lower1) for one curve & band and the variables (year2, upper2, lower2) for the second curve & band. 

 

 

View solution in original post

2 REPLIES 2
Rick_SAS
SAS Super FREQ

The reason it is working for PROC SGPLOT is because you are using the GROUP=Early_Onset option. which tells the graph to draw separate curves for each level of the Early_Onset variable.

In the GTL, you are not using that option. Instead you are using two SERIESPLOT statements and two BANDPLOT statements. But the template will render all observations, which is why the curve jumps from the upper to the lower curve.

 

The easiest solution is to rewrite the GTL to use a GROUP variable. The (more complicated) solution is to reshape the data from long to wide format. If you do that, you will need the variables (year1, upper1, lower1) for one curve & band and the variables (year2, upper2, lower2) for the second curve & band. 

 

 

Crowasaurus
Calcite | Level 5

Thanks Rick!

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
  • 2 replies
  • 260 views
  • 0 likes
  • 2 in conversation