<?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: Ascending Descending sort where in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Ascending-Descending-sort-where/m-p/788054#M251889</link>
    <description>&lt;P&gt;There are two issues with your code.&lt;/P&gt;
&lt;P&gt;Issue 1: You want to filter on a value in Country and not on a value stored in another variable named cad. The SAS log tells you that there isn't a variable CAD.&lt;/P&gt;
&lt;PRE&gt;where Country = upcase(cad);&lt;/PRE&gt;
&lt;P&gt;The syntax needs to be: where upcase(country)='CAD';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Issue 2: With Proc Sort data gets sorted in ascending order if you don't use keyword DESC / DESCENDING. The keyword ASCENDING doesn't exist with Proc Sort - it's not listed in the SAS docu so it's not available.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here your code with the fixes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data countrydata;
  input EmployeeID Province$ PostalCode$ Country$;
  cards;
737874 Ontario N0H1G0 CAD
876098 Quebec H4S1Y9 CAD
456231 Alberta T0J1K0 cad
874572 Manitoba R0K0V0 CAD
680562 Ontario K0K1A0 cad
737874 Ontario N0H1G0 CAD
874598 Quebec H4S1Y9 USA
455731 Alberta T0J1K0 cad
874372 Manitoba R0K0V0 CAD
680462 Ontario K0K1A0 cad
737374 Ontario N0H1G0 CAD
876298 Quebec H4S1Y9 CAD
456431 Alberta T0J1K0 USA
874572 Manitoba R0K0V0 CAD
6430362 Ontario K0K1A0 cad
737274 Ontario N0H1G0 CAD
873098 Quebec H4S1Y9 CAD
465633 Alberta T0J1K0 cad
874357 Manitoba R0K0V0 CAD
6834562 Ontario K0K1A0 cad
;

data countrydata2;
  set countrydata;
  where upcase(Country) = 'CAD';
run;

Proc sort data= countrydata2 out = subsetme nodupkey;
  by Country descending PostalCode;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 03 Jan 2022 01:51:17 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2022-01-03T01:51:17Z</dc:date>
    <item>
      <title>Ascending Descending sort where</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ascending-Descending-sort-where/m-p/788053#M251888</link>
      <description>&lt;P&gt;Hello team,&lt;/P&gt;
&lt;P&gt;This code doesn't produce the result that is needed:&lt;/P&gt;
&lt;PRE&gt;data countrydata;

input EmployeeID Province$ PostalCode$ Country$;

cards;

737874 Ontario N0H1G0 CAD

876098 Quebec H4S1Y9 CAD

456231 Alberta T0J1K0 cad

874572 Manitoba R0K0V0 CAD

680562 Ontario K0K1A0 cad

737874 Ontario N0H1G0 CAD

874598 Quebec H4S1Y9 USA

455731 Alberta T0J1K0 cad

874372 Manitoba R0K0V0 CAD

680462 Ontario K0K1A0 cad

737374 Ontario N0H1G0 CAD

876298 Quebec H4S1Y9 CAD

456431 Alberta T0J1K0 USA

874572 Manitoba R0K0V0 CAD

6430362 Ontario K0K1A0 cad

737274 Ontario N0H1G0 CAD

873098 Quebec H4S1Y9 CAD

465633 Alberta T0J1K0 cad

874357 Manitoba R0K0V0 CAD

6834562 Ontario K0K1A0 cad

run;

data countrydata2;
set countrydata;
where Country = upcase(cad);
run;

Proc sort data= countrydata2 out = subsetme nodupkey;
by ascending Country descending PostalCode;
run;&lt;/PRE&gt;
&lt;P&gt;If we want to use ascending, can we do that?&lt;/P&gt;
&lt;P&gt;where Country = upcase(cad); doesn't filter the data.&lt;/P&gt;
&lt;P&gt;Any help is greatly appreciated.&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;BlueBlue&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jan 2022 01:38:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ascending-Descending-sort-where/m-p/788053#M251888</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2022-01-03T01:38:09Z</dc:date>
    </item>
    <item>
      <title>Re: Ascending Descending sort where</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ascending-Descending-sort-where/m-p/788054#M251889</link>
      <description>&lt;P&gt;There are two issues with your code.&lt;/P&gt;
&lt;P&gt;Issue 1: You want to filter on a value in Country and not on a value stored in another variable named cad. The SAS log tells you that there isn't a variable CAD.&lt;/P&gt;
&lt;PRE&gt;where Country = upcase(cad);&lt;/PRE&gt;
&lt;P&gt;The syntax needs to be: where upcase(country)='CAD';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Issue 2: With Proc Sort data gets sorted in ascending order if you don't use keyword DESC / DESCENDING. The keyword ASCENDING doesn't exist with Proc Sort - it's not listed in the SAS docu so it's not available.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here your code with the fixes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data countrydata;
  input EmployeeID Province$ PostalCode$ Country$;
  cards;
737874 Ontario N0H1G0 CAD
876098 Quebec H4S1Y9 CAD
456231 Alberta T0J1K0 cad
874572 Manitoba R0K0V0 CAD
680562 Ontario K0K1A0 cad
737874 Ontario N0H1G0 CAD
874598 Quebec H4S1Y9 USA
455731 Alberta T0J1K0 cad
874372 Manitoba R0K0V0 CAD
680462 Ontario K0K1A0 cad
737374 Ontario N0H1G0 CAD
876298 Quebec H4S1Y9 CAD
456431 Alberta T0J1K0 USA
874572 Manitoba R0K0V0 CAD
6430362 Ontario K0K1A0 cad
737274 Ontario N0H1G0 CAD
873098 Quebec H4S1Y9 CAD
465633 Alberta T0J1K0 cad
874357 Manitoba R0K0V0 CAD
6834562 Ontario K0K1A0 cad
;

data countrydata2;
  set countrydata;
  where upcase(Country) = 'CAD';
run;

Proc sort data= countrydata2 out = subsetme nodupkey;
  by Country descending PostalCode;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jan 2022 01:51:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ascending-Descending-sort-where/m-p/788054#M251889</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-01-03T01:51:17Z</dc:date>
    </item>
  </channel>
</rss>

