Dear All,
Could anyone help to add a y-axis break please? see data and SAS code below. I use SAS 9.4.
thanks
John
data data;
input time $ Y1 Y2 ;
datalines;
A 1994
B 1944
C 1964
D 2240 24
E 2260 25.8
F 2240 22.8
G 1940 -3.1
;
run;
proc sgplot data=data ;
xaxis label='time' grid ;
yaxis label='Y' grid;
series x=time y=Y1/ lineattrs=(pattern=dash color=black thickness=2)
markers markerattrs =(size=11 color=black symbol=circle)
legendlabel="Y1" name='1';
series x=time y=Y2/ lineattrs=(pattern=solid color=black thickness=2)
markers markerattrs =(size=11 color=black symbol=circlefilled)
legendlabel="Y2" name='2';
keylegend "1" "2" ;
run;
Here you go:
proc template;
define statgraph sgplot;
begingraph /;
layout overlay / xaxisopts=( Label="time" labelFitPolicy=Split type=discrete discreteopts=( TickValueFitPolicy=SplitRotate ) griddisplay=on )
yaxisopts=( Label="Y" type=linear linearopts=( includeRanges=(-10-30 1920-2300 ) ) griddisplay=on );
SeriesPlot X=time Y=Y1 / primary=true display=(markers) Markerattrs=( Color=CX000000 Symbol=CIRCLE Size=11)
Lineattrs=( Color=CX000000 Pattern=20 Thickness=2) LegendLabel="Y1" NAME="1";
SeriesPlot X=time Y=Y2 / display=(markers) Markerattrs=( Color=CX000000 Symbol=CIRCLEFILLED Size=11)
Lineattrs=( Color=CX000000 Pattern=1 Thickness=2) LegendLabel="Y2" NAME="2";
DiscreteLegend "1" "2" / Location=Outside;
endlayout;
endgraph;
end;
run;
proc sgrender data=data template=sgplot; run;
Use the ranges option:
proc sgplot data= brokenaxis ;
xaxis label='time' grid ;
yaxis label='Y' grid ranges = (-10-30 1920-2300);
series x=time y=Y1/ lineattrs=(pattern=dash color=black thickness=2)
markers markerattrs =(size=11 color=black symbol=circle)
legendlabel="Y1" name='1';
series x=time y=Y2/ lineattrs=(pattern=solid color=black thickness=2)
markers markerattrs =(size=11 color=black symbol=circlefilled)
legendlabel="Y2" name='2';
keylegend "1" "2" ;
run;
Dear plf515,
Many thanks for your help. Did you change the dataset? SAS does not run with your modified code. Any suggestion?
Thanks!
John
It ran for me. What versiin of SAS are you using?
I am on 9.4
Peter
Dear Plf515, Ballardw, and Gergely,
I use SAS 9.4 as well. Even I use correct dataset name. I still got error message (see below). Gergely' code is fine but it is not what I want.
thanks! John
15 proc sgplot data= data ;
16 xaxis label='time' grid ;
17 yaxis label='Y' grid ranges = (-10-30 1920-2300);
---
79
1 -
-
79
1 -
-
79
1 -
-
79
1 -
-
79
ERROR 79-322: Expecting a -.
18
19 series x=time y=Y1/ lineattrs=(pattern=dash color=black thickness=2)
1 -
-
79
I believe the two of you are using two different maintenance releases of SAS 9.4. In SAS 9.4m1, there was code added for the RANGES option, but it was not working properly (the option is also not documented at 9.4m1). At SAS 9.4m2, the option is working and documented. If you need axis breaks at SAS 9.4m1, you can use GTL to get them.
Hi Dan,
Thanks for this clarification ! Would you mind using this example to show the line (series) plot with a Y- axis break by GTL? I have never used the GTL before.
thanks in advise!
data data;
input time $ Y1 Y2 ;
datalines;
A 1994
B 1944
C 1964
D 2240 24
E 2260 25.8
F 2240 22.8
G 1940 -3.1
;
run;
proc sgplot data=data ;
xaxis label='time' grid ;
yaxis label='Y' grid;
series x=time y=Y1/ lineattrs=(pattern=dash color=black thickness=2)
markers markerattrs =(size=11 color=black symbol=circle)
legendlabel="Y1" name='1';
series x=time y=Y2/ lineattrs=(pattern=solid color=black thickness=2)
markers markerattrs =(size=11 color=black symbol=circlefilled)
legendlabel="Y2" name='2';
keylegend "1" "2" ;
run;
Here you go:
proc template;
define statgraph sgplot;
begingraph /;
layout overlay / xaxisopts=( Label="time" labelFitPolicy=Split type=discrete discreteopts=( TickValueFitPolicy=SplitRotate ) griddisplay=on )
yaxisopts=( Label="Y" type=linear linearopts=( includeRanges=(-10-30 1920-2300 ) ) griddisplay=on );
SeriesPlot X=time Y=Y1 / primary=true display=(markers) Markerattrs=( Color=CX000000 Symbol=CIRCLE Size=11)
Lineattrs=( Color=CX000000 Pattern=20 Thickness=2) LegendLabel="Y1" NAME="1";
SeriesPlot X=time Y=Y2 / display=(markers) Markerattrs=( Color=CX000000 Symbol=CIRCLEFILLED Size=11)
Lineattrs=( Color=CX000000 Pattern=1 Thickness=2) LegendLabel="Y2" NAME="2";
DiscreteLegend "1" "2" / Location=Outside;
endlayout;
endgraph;
end;
run;
proc sgrender data=data template=sgplot; run;
Hi Dan,
Many Thanks!!!
John
plf515 used a different data set name if you just copied and ran his code you would need to make sure the DATA= is your data set.
If you get an error when running someone's code it is a very good idea to post any errors.
Thanks
ballardw wrote:
plf515 used a different data set name if you just copied and ran his code you would need to make sure the DATA= is your data set.
If you get an error when running someone's code it is a very good idea to post any errors.
In this specific case I would use y2axis:
proc sgplot data=data ;
xaxis label='time' grid ;
yaxis label='Y1' grid;
y2axis label='Y2' grid;
series x=time y=Y1/ lineattrs=(pattern=dash color=black thickness=2)
markers markerattrs =(size=11 color=black symbol=circle)
legendlabel="Y1" name='1';
series x=time y=Y2/ lineattrs=(pattern=solid color=black thickness=2)
markers markerattrs =(size=11 color=black symbol=circlefilled)
legendlabel="Y2" name='2'
y2axis;
keylegend "1" "2" ;
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.