<?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 Re: Can I order one variable in Ascending and another in descending order in Hash? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Can-I-order-one-variable-in-Ascending-and-another-in-descending/m-p/56520#M12099</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It&amp;nbsp; almost cann't. But there is a&amp;nbsp; workaround way.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data have;
input id&amp;nbsp; var @@;
cards;
1 2 1 3 10 6 8 5 10 7 8 2
;
run;

data _null_;
declare hash h(ordered: 'Ascending',multidata:'yes');
&amp;nbsp;&amp;nbsp;&amp;nbsp; h.definekey('id','_var');
&amp;nbsp;&amp;nbsp;&amp;nbsp; h.definedata('id','var');
&amp;nbsp;&amp;nbsp;&amp;nbsp; h.definedone();
do until(last);
 set have end=last;
 _var=-1*var;
 h.add();
end;
&amp;nbsp;&amp;nbsp;&amp;nbsp; h.output(dataset:'want');
run;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 06 Apr 2012 01:48:44 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2012-04-06T01:48:44Z</dc:date>
    <item>
      <title>Can I order one variable in Ascending and another in descending order in Hash?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-order-one-variable-in-Ascending-and-another-in-descending/m-p/56519#M12098</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="color: navy; font-size: 12pt; background: white; font-family: 'Courier New';"&gt;&lt;STRONG&gt;Hi,&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: navy; font-size: 12pt; background: white; font-family: 'Courier New';"&gt;&lt;STRONG&gt;I like to have the output dataset first ordered by ascending Id then by descending var. Is it possible in hash?&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: navy; font-size: 12pt; background: white; font-family: 'Courier New';"&gt;&lt;STRONG&gt;Thanks - Linlin&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: navy; font-size: 12pt; background: white; font-family: 'Courier New';"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt; have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 12pt;"&gt;input&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt; id&amp;nbsp; var @@;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 12pt;"&gt;cards&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 12pt;"&gt;1 2 1 3 10 6 8 5 10 7 8 2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: navy; font-size: 12pt; background: white; font-family: 'Courier New';"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 12pt;"&gt;_null_&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 12pt;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt; have (obs=&lt;/SPAN&gt;&lt;SPAN style="color: teal; font-size: 12pt; background: white; font-family: 'Courier New';"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: red; font-size: 12pt;"&gt;dcl&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt; hash h( dataset: &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple; font-size: 12pt;"&gt;'have'&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;, ordered: &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple; font-size: 12pt;"&gt;'Ascending'&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;,multidata:&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple; font-size: 12pt;"&gt;'yes'&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;h.definekey(&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple; font-size: 12pt;"&gt;'id'&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple; font-size: 12pt;"&gt;'var'&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;h.definedata(all:&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple; font-size: 12pt;"&gt;'y'&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;h.definedone();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;h.output(dataset:&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple; font-size: 12pt;"&gt;'want'&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: navy; font-size: 12pt; background: white; font-family: 'Courier New';"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;I want the output like below:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'SAS Monospace'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Obs&amp;nbsp;&amp;nbsp;&amp;nbsp; id&amp;nbsp;&amp;nbsp;&amp;nbsp; var&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'SAS Monospace'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'SAS Monospace'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'SAS Monospace'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'SAS Monospace'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'SAS Monospace'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 7&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'SAS Monospace'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Apr 2012 19:28:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-order-one-variable-in-Ascending-and-another-in-descending/m-p/56519#M12098</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-04-05T19:28:55Z</dc:date>
    </item>
    <item>
      <title>Re: Can I order one variable in Ascending and another in descending order in Hash?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-order-one-variable-in-Ascending-and-another-in-descending/m-p/56520#M12099</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It&amp;nbsp; almost cann't. But there is a&amp;nbsp; workaround way.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data have;
input id&amp;nbsp; var @@;
cards;
1 2 1 3 10 6 8 5 10 7 8 2
;
run;

data _null_;
declare hash h(ordered: 'Ascending',multidata:'yes');
&amp;nbsp;&amp;nbsp;&amp;nbsp; h.definekey('id','_var');
&amp;nbsp;&amp;nbsp;&amp;nbsp; h.definedata('id','var');
&amp;nbsp;&amp;nbsp;&amp;nbsp; h.definedone();
do until(last);
 set have end=last;
 _var=-1*var;
 h.add();
end;
&amp;nbsp;&amp;nbsp;&amp;nbsp; h.output(dataset:'want');
run;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Apr 2012 01:48:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-order-one-variable-in-Ascending-and-another-in-descending/m-p/56520#M12099</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-04-06T01:48:44Z</dc:date>
    </item>
    <item>
      <title>Re: Can I order one variable in Ascending and another in descending order in Hash?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-order-one-variable-in-Ascending-and-another-in-descending/m-p/56521#M12100</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ksharp, very slick! though I am wondering if there is a way you can 'walk around' upon character variables.&lt;img id="smileywink" class="emoticon emoticon-smileywink" src="https://communities.sas.com/i/smilies/16x16_smiley-wink.png" alt="Smiley Wink" title="Smiley Wink" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Apr 2012 02:33:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-order-one-variable-in-Ascending-and-another-in-descending/m-p/56521#M12100</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-04-06T02:33:47Z</dc:date>
    </item>
    <item>
      <title>Re: Can I order one variable in Ascending and another in descending order in Hash?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-order-one-variable-in-Ascending-and-another-in-descending/m-p/56522#M12101</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you Ksharp! You are always helpful.&amp;nbsp; - Linlin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Apr 2012 03:46:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-order-one-variable-in-Ascending-and-another-in-descending/m-p/56522#M12101</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-04-06T03:46:52Z</dc:date>
    </item>
    <item>
      <title>Re: Can I order one variable in Ascending and another in descending order in Hash?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-order-one-variable-in-Ascending-and-another-in-descending/m-p/56523#M12102</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Using Ksharp's approach one could convert a string to its octal representation and use this value for sorting.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code example below uses only the first five characters for sorting (as the octal representation ends up as a 15 digit number). I believe this is most of the time sufficient.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input id&amp;nbsp; var:$9. @@;&lt;BR /&gt;cards;&lt;BR /&gt;1 ab 1 xyz 10 D9a 8 test 10 Xyz 8 9This&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;&amp;nbsp; declare hash h(ordered: 'Ascending',multidata:'yes');&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; h.definekey('id','_var');&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; h.definedata('id','var');&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; h.definedone();&lt;BR /&gt;&amp;nbsp; do until(last);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; set have end=last;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; _var=-1*input(put(subpad(var,1,5),octal.),15.);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; h.add();&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp; h.output(dataset:'want');&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 08 Apr 2012 01:31:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-order-one-variable-in-Ascending-and-another-in-descending/m-p/56523#M12102</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2012-04-08T01:31:34Z</dc:date>
    </item>
    <item>
      <title>Re: Can I order one variable in Ascending and another in descending order in Hash?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-order-one-variable-in-Ascending-and-another-in-descending/m-p/56524#M12103</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Linlin: I had suggested using the rank function, but I'm retracting that suggestion as it would only work for one character strings.&amp;nbsp; It worked for your example because the first character of the string was the only one that was needed to differentiate (correctly) order the strings.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 08 Apr 2012 02:03:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-order-one-variable-in-Ascending-and-another-in-descending/m-p/56524#M12103</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-04-08T02:03:32Z</dc:date>
    </item>
    <item>
      <title>Re: Can I order one variable in Ascending and another in descending order in Hash?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-order-one-variable-in-Ascending-and-another-in-descending/m-p/56525#M12104</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you Patrick and Art! Both methods worked great!&amp;nbsp; - Linlin&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Art's method:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input id&amp;nbsp; var:$9. @@;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1 ab 1 xyz 10 D9a 8 test 10 Xyz 8 9This&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; declare hash h(ordered: 'Ascending',multidata:'yes');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; h.definekey('id','_var');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; h.definedata('id','var');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; h.definedone();&lt;/P&gt;&lt;P&gt;&amp;nbsp; do until(last);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set have end=last;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; _var=-1*rank(var);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; h.add();&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; h.output(dataset:'want');&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc print;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 08 Apr 2012 11:33:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-order-one-variable-in-Ascending-and-another-in-descending/m-p/56525#M12104</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-04-08T11:33:12Z</dc:date>
    </item>
    <item>
      <title>Re: Can I order one variable in Ascending and another in descending order in Hash?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-order-one-variable-in-Ascending-and-another-in-descending/m-p/56526#M12105</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Art,&lt;/P&gt;&lt;P&gt;I think Rank() can only handle one character ,not for a string, so it is not a good idea.&lt;/P&gt;&lt;P&gt;E.X.(wrong result)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data have;
input id&amp;nbsp; var:$9. @@;
cards;
1 aa 1 ayz 10 Xaa 8 test 10 Xyz 8 This
;
run;

data _null_;
&amp;nbsp; declare hash h(ordered: 'Ascending',multidata:'yes');
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; h.definekey('id','_var');
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; h.definedata('id','var');
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; h.definedone();
&amp;nbsp; do until(last);
&amp;nbsp;&amp;nbsp; set have end=last;
&amp;nbsp;&amp;nbsp; _var=-1*rank(var);
&amp;nbsp;&amp;nbsp; h.add();
&amp;nbsp; end;
&amp;nbsp; h.output(dataset:'want');
run;


&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Apr 2012 04:20:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-order-one-variable-in-Ascending-and-another-in-descending/m-p/56526#M12105</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-04-09T04:20:20Z</dc:date>
    </item>
    <item>
      <title>Re: Can I order one variable in Ascending and another in descending order in Hash?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-order-one-variable-in-Ascending-and-another-in-descending/m-p/56527#M12106</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Patrick,&lt;/P&gt;&lt;P&gt;As always, I am amazing with your idea . But unfortunately you only process the first five character.&lt;/P&gt;&lt;P&gt;I have an alternative way.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Apr 2012 04:48:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-order-one-variable-in-Ascending-and-another-in-descending/m-p/56527#M12106</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-04-09T04:48:08Z</dc:date>
    </item>
    <item>
      <title>Re: Can I order one variable in Ascending and another in descending order in Hash?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-order-one-variable-in-Ascending-and-another-in-descending/m-p/56528#M12107</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is. But I don't like it yet.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data have;
input id&amp;nbsp; var &amp;amp; $9. @@;
cards;
1 a bc&amp;nbsp; 1 a cb&amp;nbsp;&amp;nbsp; 10 D9a&amp;nbsp;&amp;nbsp; 8 test&amp;nbsp;&amp;nbsp; 10 Xyz&amp;nbsp;&amp;nbsp;&amp;nbsp; 8 9This
;
run;

data _null_;
if 0 then set have;
&amp;nbsp; declare hash h1(dataset:'have',ordered: 'Ascending');
&amp;nbsp; declare hiter hi1('h1');
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; h1.definekey('id');
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; h1.definedata('id');
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; h1.definedone();
if 0 then set have(rename=(id=_id));
&amp;nbsp; declare hash h2(dataset:'have(rename=(id=_id))',ordered:'D',multidata:'Y');
&amp;nbsp; declare hiter hi2('h2');
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; h2.definekey('_id','var');
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; h2.definedata('_id','var');
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; h2.definedone();
&amp;nbsp; declare hash h3(ordered:'A');
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; h3.definekey('count');
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; h3.definedata('id','var');
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; h3.definedone();

do while(hi1.next()=0);
 do while(hi2.next()=0);
&amp;nbsp; if id=_id then do;count+1;h3.add(); end;
 end;
end;
h3.output(dataset:'want');
run;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Apr 2012 05:18:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-order-one-variable-in-Ascending-and-another-in-descending/m-p/56528#M12107</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-04-09T05:18:04Z</dc:date>
    </item>
  </channel>
</rss>

