Data visualization with SAS programming

add a y-axis break

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

add a y-axis break

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;


Accepted Solutions
Solution
‎04-30-2015 03:23 PM
SAS Super FREQ
Posts: 864

Re: add a y-axis break

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;

View solution in original post


All Replies
Frequent Contributor
Posts: 140

Re: add a y-axis break

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;

Occasional Contributor
Posts: 14

Re: add a y-axis break

Dear plf515,

Many thanks for your help. Did you change the dataset?  SAS does not run with your modified code.  Any suggestion?

Thanks!

John

Frequent Contributor
Posts: 140

Re: add a y-axis break

It ran for me. What versiin of SAS are you using?

I am on 9.4

Peter

Occasional Contributor
Posts: 14

Re: add a y-axis break

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

SAS Super FREQ
Posts: 864

Re: add a y-axis break

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.

Occasional Contributor
Posts: 14

Re: add a y-axis break

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;

Solution
‎04-30-2015 03:23 PM
SAS Super FREQ
Posts: 864

Re: add a y-axis break

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;

Occasional Contributor
Posts: 14

Re: add a y-axis break

Hi Dan,

Many Thanks!!!

John

Grand Advisor
Posts: 9,713

Re: add a y-axis break

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.

Frequent Contributor
Posts: 140

Re: add a y-axis break

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.

SAS Employee
Posts: 340

Re: add a y-axis break

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;

Post a Question
Discussion Stats
  • 11 replies
  • 1207 views
  • 6 likes
  • 5 in conversation