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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

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

11 REPLIES 11
plf515
Lapis Lazuli | Level 10

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;

Johnlee
Calcite | Level 5

Dear plf515,

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

Thanks!

John

plf515
Lapis Lazuli | Level 10

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

I am on 9.4

Peter

Johnlee
Calcite | Level 5

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

DanH_sas
SAS Super FREQ

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.

Johnlee
Calcite | Level 5

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;

DanH_sas
SAS Super FREQ

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;

Johnlee
Calcite | Level 5

Hi Dan,

Many Thanks!!!

John

ballardw
Super User

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.

plf515
Lapis Lazuli | Level 10

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.

gergely_batho
SAS Employee

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 11 replies
  • 4183 views
  • 6 likes
  • 5 in conversation