Data visualization with SAS programming

Setting the origin (axis crossing) in sgplot

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Setting the origin (axis crossing) in sgplot

I'm trying to generate a scatter plot inwhich I can set the axis crossing point.  The code I've tried so far is:

proc sgplot data=pi.LdIcuHospState;
where groupid=1 and year(edarrivaldate)=2015 and FacilityIDo ne "State";
title '2015 Survival Group 1';
scatter x=IssAvg_Ldr y=LiveDieAvgr  / group=FacilityIdo xorigin=&y_LD_Avg yorigin=&y_LD_Avg;
run;

 

But - I get an error message when I use the xorigin and yorigin statements. 

ERROR 22-322: Syntax error, expecting one of the following: ;, ATTRID, CLUSTERWIDTH, COLORMODEL,
              COLORRESPONSE, DATALABEL, DATALABELATTRS, DATALABELPOS, DATASKIN, DISCRETEOFFSET,
              ERRORBARATTRS, FILLEDOUTLINEDMARKERS, FREQ, GROUP, GROUPDISPLAY, GROUPORDER,
              JITTER, JITTERWIDTH, LABELSTRIP, LEGENDLABEL, MARKERATTRS, MARKERCHAR,
              MARKERCHARATTRS, MARKERFILLATTRS, MARKEROUTLINEATTRS, NAME, NOERRORCAPS,
              NOMISSINGGROUP, RATTRID, SPLITCHAR, SPLITCHARNODROP, SPLITJUSTIFY, TIP, TIPFORMAT,
              TIPLABEL, TRANSPARENCY, URL, X2AXIS, XERRORLOWER, XERRORUPPER, Y2AXIS, YERRORLOWER,
              YERRORUPPER.
ERROR 76-322: Syntax error, statement will be ignored

 

 

I'd like the output graph to look like the picture below.

 

GraphPicture2.jpg.

 

 

Suggestions?  Thanks!

 


Accepted Solutions
Solution
‎06-07-2017 02:20 PM
SAS Super FREQ
Posts: 3,547

Re: Setting the origin (axis crossing) in sgplot

The documentation of the SCATTER statement is here. Notice there are no XORIGIN or YORIGIN statements.

 

What you propose is not simple to do.  When I want to indicate an average value or some other reference value, I use the REFLINE statement to add vertical and horizontal reference lines, like this:

 

%let x_ave =  62.3;
%let y_ave = 100;

proc sgplot data=sashelp.class;
format Name $2.;
scatter x=Height y=Weight / datalabel=Name;
refline &x_ave / axis=x;
refline &y_ave / axis=y;
xaxis grid;
yaxis grid;
run;

View solution in original post


All Replies
Solution
‎06-07-2017 02:20 PM
SAS Super FREQ
Posts: 3,547

Re: Setting the origin (axis crossing) in sgplot

The documentation of the SCATTER statement is here. Notice there are no XORIGIN or YORIGIN statements.

 

What you propose is not simple to do.  When I want to indicate an average value or some other reference value, I use the REFLINE statement to add vertical and horizontal reference lines, like this:

 

%let x_ave =  62.3;
%let y_ave = 100;

proc sgplot data=sashelp.class;
format Name $2.;
scatter x=Height y=Weight / datalabel=Name;
refline &x_ave / axis=x;
refline &y_ave / axis=y;
xaxis grid;
yaxis grid;
run;
SAS Super FREQ
Posts: 916

Re: Setting the origin (axis crossing) in sgplot

It is possible to do this using GTL; however, if you want to stick with the SG procedures, I agree with RIck that using REFLINEs can give you a good display of this information. It also keeps the tick values out of the way of the data.

 

The SGPlot Procedure

 

%let x_avg=13.4;
%let y_avg=61.2;

proc sgplot data=sashelp.class noborder;
xaxis display=(noticks noline) grid;
yaxis display=(noticks noline) grid;
refline &x_avg / axis=x lineattrs=(thickness=3) label;
refline &y_avg / lineattrs=(thickness=3) label;
scatter x=age y=height / datalabel
        markerattrs=(symbol=circlefilled);
run;
New Contributor
Posts: 2

Re: Setting the origin (axis crossing) in sgplot

Thanks! 

SAS Super FREQ
Posts: 1,118

Re: Setting the origin (axis crossing) in sgplot

Cartesean axes are supported in GTL.  You can use the ORIGIN option in the LINEAROPTS of the XAXISOPTS and YAXISOPTS.  This is not supported in SGPLOT.  You can use the TMPLOUT option on the SGPLOT procedure to write out the GTL generated by the SGPLOT procedure for your code.  Then, you can read in the GTL, and add the ORIGIN= optiion in the XAXISOPTS and YAXISOPTS bundles to get what you want.

☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 171 views
  • 2 likes
  • 4 in conversation