<?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 SAS Tip: Sorting an Array in Descending Order in SAS Tips from the Community</title>
    <link>https://communities.sas.com/t5/SAS-Tips-from-the-Community/SAS-Tip-Sorting-an-Array-in-Descending-Order/m-p/442561#M145</link>
    <description>&lt;P&gt;Call routines &lt;A href="http://go.documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p0exzteatvicqkn1bzyzs0qaecy1.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;SORTN&lt;/A&gt;&amp;nbsp;and &lt;A href="http://go.documentation.sas.com/?cdcId=vdmmlcdc&amp;amp;cdcVersion=8.1&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n00aheqlqf6qdln1og24z2hcsfd6.htm&amp;amp;locale=en" target="_self"&gt;SORTC&lt;/A&gt;&amp;nbsp;can order an array in ascending order only. What if you want to order it in descending order? Here is an easy way!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE lang="sas"&gt;data _null_;
  array arr[*] v1-v5 (1 2 3 4 5);
  put "before:" (v1-v5) (= +1);
  /* reverse the variable list in a new array definition and sort */
  array rev[*] v5-v1;
call sortn(of rev[*]);
put "after :" (v1-v5) (= +1);
run;
/* on log
   before: v1=1  v2=2  v3=3  v4=4  v5=5
   after : v1=5  v2=4  v3=3  v4=2  v5=1
*/&lt;/PRE&gt;
&lt;P&gt;For a detailed discussion on variable lists, see &lt;A href="http://analytics.ncsu.edu/sesug/2011/BB05.Schreier.pdf" target="_self"&gt;Using SAS Variable Lists Effectively&lt;/A&gt;&amp;nbsp;|Schreier (2011).&lt;/P&gt;
&lt;HR /&gt;
&lt;P&gt;&lt;BR /&gt;Thanks to chang_y_chung&amp;nbsp;for sharing this tip on sasCommunity.org.&lt;/P&gt;</description>
    <pubDate>Tue, 27 Mar 2018 13:28:28 GMT</pubDate>
    <dc:creator>SAS_Tipster</dc:creator>
    <dc:date>2018-03-27T13:28:28Z</dc:date>
    <item>
      <title>SAS Tip: Sorting an Array in Descending Order</title>
      <link>https://communities.sas.com/t5/SAS-Tips-from-the-Community/SAS-Tip-Sorting-an-Array-in-Descending-Order/m-p/442561#M145</link>
      <description>&lt;P&gt;Call routines &lt;A href="http://go.documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p0exzteatvicqkn1bzyzs0qaecy1.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;SORTN&lt;/A&gt;&amp;nbsp;and &lt;A href="http://go.documentation.sas.com/?cdcId=vdmmlcdc&amp;amp;cdcVersion=8.1&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n00aheqlqf6qdln1og24z2hcsfd6.htm&amp;amp;locale=en" target="_self"&gt;SORTC&lt;/A&gt;&amp;nbsp;can order an array in ascending order only. What if you want to order it in descending order? Here is an easy way!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE lang="sas"&gt;data _null_;
  array arr[*] v1-v5 (1 2 3 4 5);
  put "before:" (v1-v5) (= +1);
  /* reverse the variable list in a new array definition and sort */
  array rev[*] v5-v1;
call sortn(of rev[*]);
put "after :" (v1-v5) (= +1);
run;
/* on log
   before: v1=1  v2=2  v3=3  v4=4  v5=5
   after : v1=5  v2=4  v3=3  v4=2  v5=1
*/&lt;/PRE&gt;
&lt;P&gt;For a detailed discussion on variable lists, see &lt;A href="http://analytics.ncsu.edu/sesug/2011/BB05.Schreier.pdf" target="_self"&gt;Using SAS Variable Lists Effectively&lt;/A&gt;&amp;nbsp;|Schreier (2011).&lt;/P&gt;
&lt;HR /&gt;
&lt;P&gt;&lt;BR /&gt;Thanks to chang_y_chung&amp;nbsp;for sharing this tip on sasCommunity.org.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Mar 2018 13:28:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Tips-from-the-Community/SAS-Tip-Sorting-an-Array-in-Descending-Order/m-p/442561#M145</guid>
      <dc:creator>SAS_Tipster</dc:creator>
      <dc:date>2018-03-27T13:28:28Z</dc:date>
    </item>
  </channel>
</rss>

