<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to sort xaxis values by yaxis values in sgplot? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-sort-xaxis-values-by-yaxis-values-in-sgplot/m-p/796512#M81591</link>
    <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using sgplot to plot studentresid using the following code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;BR /&gt;proc sgplot data=second ;&lt;BR /&gt;scatter y=studentresid x=id / jitter transparency=0.5 &lt;BR /&gt;markerattrs=(symbol=CircleFilled size=12) ;&lt;BR /&gt;&lt;BR /&gt;yaxis values=(3 to 3 by 1) grid;&lt;/PRE&gt;&lt;P&gt;And I obtain the attached scatter plot. However, I would like to improve it by:&lt;/P&gt;&lt;P&gt;- sorting the xaxis by ascending values of the studentresid, from left to right&lt;/P&gt;&lt;P&gt;- ideally coloring differently the three observations with very high studentresid, above the grid line at value 3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2022-02-16 at 11.57.57.png" style="width: 670px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/68522i33DEB66DC1D02BA4/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2022-02-16 at 11.57.57.png" alt="Screenshot 2022-02-16 at 11.57.57.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 16 Feb 2022 10:59:40 GMT</pubDate>
    <dc:creator>emaneman</dc:creator>
    <dc:date>2022-02-16T10:59:40Z</dc:date>
    <item>
      <title>How to sort xaxis values by yaxis values in sgplot?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-sort-xaxis-values-by-yaxis-values-in-sgplot/m-p/796512#M81591</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using sgplot to plot studentresid using the following code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;BR /&gt;proc sgplot data=second ;&lt;BR /&gt;scatter y=studentresid x=id / jitter transparency=0.5 &lt;BR /&gt;markerattrs=(symbol=CircleFilled size=12) ;&lt;BR /&gt;&lt;BR /&gt;yaxis values=(3 to 3 by 1) grid;&lt;/PRE&gt;&lt;P&gt;And I obtain the attached scatter plot. However, I would like to improve it by:&lt;/P&gt;&lt;P&gt;- sorting the xaxis by ascending values of the studentresid, from left to right&lt;/P&gt;&lt;P&gt;- ideally coloring differently the three observations with very high studentresid, above the grid line at value 3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2022-02-16 at 11.57.57.png" style="width: 670px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/68522i33DEB66DC1D02BA4/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2022-02-16 at 11.57.57.png" alt="Screenshot 2022-02-16 at 11.57.57.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Feb 2022 10:59:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-sort-xaxis-values-by-yaxis-values-in-sgplot/m-p/796512#M81591</guid>
      <dc:creator>emaneman</dc:creator>
      <dc:date>2022-02-16T10:59:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort xaxis values by yaxis values in sgplot?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-sort-xaxis-values-by-yaxis-values-in-sgplot/m-p/796516#M81592</link>
      <description>&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* 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 &amp;gt; 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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SGPlot19.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/68523i424F24A9955DA081/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SGPlot19.png" alt="SGPlot19.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Wed, 16 Feb 2022 11:17:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-sort-xaxis-values-by-yaxis-values-in-sgplot/m-p/796516#M81592</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2022-02-16T11:17:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort xaxis values by yaxis values in sgplot?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-sort-xaxis-values-by-yaxis-values-in-sgplot/m-p/796519#M81593</link>
      <description>&lt;P&gt;I just re-read the OP and noticed that the request was for ASCENDING values of studentized residuals. To get that, remove the &lt;STRONG&gt;DESCENDING&lt;/STRONG&gt; keyword from the PROC RANK statement.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Feb 2022 11:35:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-sort-xaxis-values-by-yaxis-values-in-sgplot/m-p/796519#M81593</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2022-02-16T11:35:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort xaxis values by yaxis values in sgplot?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-sort-xaxis-values-by-yaxis-values-in-sgplot/m-p/796522#M81594</link>
      <description>&lt;P&gt;Thank you Rick! Fast, brilliant, and precise, as usual!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Feb 2022 12:07:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-sort-xaxis-values-by-yaxis-values-in-sgplot/m-p/796522#M81594</guid>
      <dc:creator>emaneman</dc:creator>
      <dc:date>2022-02-16T12:07:21Z</dc:date>
    </item>
  </channel>
</rss>

