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.
.
Suggestions? Thanks!
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;
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;
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.
%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;
Thanks!
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.
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.