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

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

 

Screenshot 2022-02-16 at 11.57.57.png

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

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.

View solution in original post

3 REPLIES 3
Rick_SAS
SAS Super FREQ

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;

 

SGPlot19.png

Rick_SAS
SAS Super FREQ

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.

emaneman
Pyrite | Level 9

Thank you Rick! Fast, brilliant, and precise, as usual! 

sas-innovate-white.png

Missed SAS Innovate in Orlando?

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.

 

Register now

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 841 views
  • 0 likes
  • 2 in conversation