Dear all,
I am using sgplot to plot studentresid using the following code
proc sgplot data=second ;
scatter y=studentresid x=id / jitter transparency=0.5
markerattrs=(symbol=CircleFilled size=12) ;
yaxis values=(3 to 3 by 1) grid;
And I obtain the attached scatter plot. However, I would like to improve it by:
- sorting the xaxis by ascending values of the studentresid, from left to right
- ideally coloring differently the three observations with very high studentresid, above the grid line at value 3
I just re-read the OP and noticed that the request was for ASCENDING values of studentized residuals. To get that, remove the DESCENDING keyword from the PROC RANK statement.
Sort by the rank of the Y variable and add an indicator variable that colors the markers for which studentized resid is larger than 3.
/* create fake data */
data second;
call streaminit(1);
do id = 1 to 220;
studentresid = rand("Normal", 2, 0.1);
if id=4 then studentresid=6;
else if id=55 then studentresid=5;
else if id=130 then studentresid=4;
output;
end;
run;
/* sort according to rank */
proc rank data=second out=Want1 descending;
var studentresid;
ranks Rank;
run;
proc sort data=Want1; by Rank; run;
/* add indicator variable for outlier */
data Want;
set Want1;
Outlier = (studentresid > 3);
run;
proc sgplot data=Want;
scatter y=studentresid x=Rank / jitter transparency=0.5 GROUP=Outlier
markerattrs=(symbol=CircleFilled size=12) ;
yaxis values=(3 to 3 by 1) grid label="Studentized Residuals";
xaxis display=(nolabel);
run;
I just re-read the OP and noticed that the request was for ASCENDING values of studentized residuals. To get that, remove the DESCENDING keyword from the PROC RANK statement.
Thank you Rick! Fast, brilliant, and precise, as usual!
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.