<?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: variable sort using datastep in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/variable-sort-using-datastep/m-p/569406#M11804</link>
    <description>&lt;P&gt;It is rarely a good idea to do this directly in the Data Step. However, if it has to be in a data step, you can use a hash object like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
    if 0 then set countries;
    declare hash h(dataset:'countries', ordered:'d');
    h.definekey('Population');
    h.definedata(all:'Y');
    h.definedone();

    h.output(dataset:'want');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 27 Jun 2019 12:52:55 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2019-06-27T12:52:55Z</dc:date>
    <item>
      <title>variable sort using datastep</title>
      <link>https://communities.sas.com/t5/New-SAS-User/variable-sort-using-datastep/m-p/569398#M11798</link>
      <description>i want sort the Population from highest to lowest in datastep&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import datafile ="C:\Users\Anand\Desktop\country_wise_population.xlsx" 
out=countries
dbms=xlsx	;
run;


data population;
set countries;
by  descending Population		;
run;
	&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Jun 2019 12:41:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/variable-sort-using-datastep/m-p/569398#M11798</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2019-06-27T12:41:49Z</dc:date>
    </item>
    <item>
      <title>Re: variable sort using datastep</title>
      <link>https://communities.sas.com/t5/New-SAS-User/variable-sort-using-datastep/m-p/569400#M11800</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265860"&gt;@BrahmanandaRao&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;i want sort the Population from highest to lowest in datastep
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import datafile ="C:\Users\Anand\Desktop\country_wise_population.xlsx" 
out=countries
dbms=xlsx	;
run;
	&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Use PROC SORT instead of a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=countries;
    by descending population;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Jun 2019 12:43:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/variable-sort-using-datastep/m-p/569400#M11800</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-06-27T12:43:48Z</dc:date>
    </item>
    <item>
      <title>Re: variable sort using datastep</title>
      <link>https://communities.sas.com/t5/New-SAS-User/variable-sort-using-datastep/m-p/569402#M11802</link>
      <description>&lt;P&gt;using datastep not in proc step&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2019 12:46:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/variable-sort-using-datastep/m-p/569402#M11802</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2019-06-27T12:46:14Z</dc:date>
    </item>
    <item>
      <title>Re: variable sort using datastep</title>
      <link>https://communities.sas.com/t5/New-SAS-User/variable-sort-using-datastep/m-p/569405#M11803</link>
      <description>&lt;P&gt;It's a lot more difficult (if it is even possible at all) to sort using a DATA step.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2019 12:49:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/variable-sort-using-datastep/m-p/569405#M11803</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-06-27T12:49:29Z</dc:date>
    </item>
    <item>
      <title>Re: variable sort using datastep</title>
      <link>https://communities.sas.com/t5/New-SAS-User/variable-sort-using-datastep/m-p/569406#M11804</link>
      <description>&lt;P&gt;It is rarely a good idea to do this directly in the Data Step. However, if it has to be in a data step, you can use a hash object like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
    if 0 then set countries;
    declare hash h(dataset:'countries', ordered:'d');
    h.definekey('Population');
    h.definedata(all:'Y');
    h.definedone();

    h.output(dataset:'want');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Jun 2019 12:52:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/variable-sort-using-datastep/m-p/569406#M11804</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-06-27T12:52:55Z</dc:date>
    </item>
    <item>
      <title>Re: variable sort using datastep</title>
      <link>https://communities.sas.com/t5/New-SAS-User/variable-sort-using-datastep/m-p/569409#M11805</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;It is rarely a good idea to do this directly in the Data Step. However, if it has to be in a data step, you can use a hash object like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
    if 0 then set countries;
    declare hash h(dataset:'countries', ordered:'d');
    h.definekey('Population');
    h.definedata(all:'Y');
    h.definedone();

    h.output(dataset:'want');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;Yes, indeed it is rarely a good idea to write your own code to replicate what SAS has already programmed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So to &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265860"&gt;@BrahmanandaRao&lt;/a&gt;&amp;nbsp;Why would anyone want to use an advanced technique like hash objects, when a beginner method like PROC SORT is available which does the same thing and probably does it a lot faster than hash objects?&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2019 12:59:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/variable-sort-using-datastep/m-p/569409#M11805</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-06-27T12:59:37Z</dc:date>
    </item>
    <item>
      <title>Re: variable sort using datastep</title>
      <link>https://communities.sas.com/t5/New-SAS-User/variable-sort-using-datastep/m-p/569410#M11806</link>
      <description>NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds 211 h.definedata(all:'Y'); 212 h.definedone(); 213 214 h.output(dataset:'want'); 215 run; 216 data _null_; 217 if 0 then set countries; 218 declare hash h(dataset:'countries', ordered:'d'); - 567 219 h.definekey('Population'); ----------- 557 ERROR: DATA STEP Component Object failure. Aborted during the COMPILATION phase. ERROR 567-185: Variable H already defined. ERROR 557-185: Variable h is not an object. NOTE: The SAS System stopped processing this step because of errors. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds 220 h.definedata(all:'Y'); 221 h.definedone(); 222 223 h.output(dataset:'want'); 224 run;</description>
      <pubDate>Thu, 27 Jun 2019 12:59:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/variable-sort-using-datastep/m-p/569410#M11806</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2019-06-27T12:59:39Z</dc:date>
    </item>
    <item>
      <title>Re: variable sort using datastep</title>
      <link>https://communities.sas.com/t5/New-SAS-User/variable-sort-using-datastep/m-p/569413#M11807</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265860"&gt;@BrahmanandaRao&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;using datastep not in proc step&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Why?&amp;nbsp; There is no good reason I can think of that would require you to implement a sorting algorithm in a data step.&lt;/P&gt;
&lt;P&gt;If you want to process the data in a specific order then sort it first and then run your data step.&lt;/P&gt;
&lt;P&gt;If you really do not have the space to save a sorted copy of the data you might want to create a PROC SQL view that sorts the data and read from that view.&amp;nbsp; But watch out for the space used in the UTIL folders.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create view country_pop_view as
 select *
 from countries
 order by desc population
;
quit;

data want;
  set country_pop_view ;
  by population descending;
  ...
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Jun 2019 13:13:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/variable-sort-using-datastep/m-p/569413#M11807</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-06-27T13:13:59Z</dc:date>
    </item>
    <item>
      <title>Re: variable sort using datastep</title>
      <link>https://communities.sas.com/t5/New-SAS-User/variable-sort-using-datastep/m-p/569414#M11808</link>
      <description>&lt;P&gt;0.00 sec .. That is one fast sort&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Seems like your data set has a variable named &lt;STRONG&gt;h&lt;/STRONG&gt; which conflicts with the name of the hash object. Needless to say, my code is untested as I can not see your data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, I second&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;.. Just use PROC SORT &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2019 13:17:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/variable-sort-using-datastep/m-p/569414#M11808</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-06-27T13:17:26Z</dc:date>
    </item>
    <item>
      <title>Re: variable sort using datastep</title>
      <link>https://communities.sas.com/t5/New-SAS-User/variable-sort-using-datastep/m-p/569421#M11812</link>
      <description>&lt;P&gt;Error this code&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2019 13:23:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/variable-sort-using-datastep/m-p/569421#M11812</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2019-06-27T13:23:20Z</dc:date>
    </item>
    <item>
      <title>Re: variable sort using datastep</title>
      <link>https://communities.sas.com/t5/New-SAS-User/variable-sort-using-datastep/m-p/569423#M11813</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265860"&gt;@BrahmanandaRao&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Error this code&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;??&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are probably errors since I just typed sample code into the forum instead of running it in SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want fully worked example code you need to provide sample data in the form of a data step that can be run to create the dataset.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2019 13:29:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/variable-sort-using-datastep/m-p/569423#M11813</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-06-27T13:29:31Z</dc:date>
    </item>
    <item>
      <title>Re: variable sort using datastep</title>
      <link>https://communities.sas.com/t5/New-SAS-User/variable-sort-using-datastep/m-p/569437#M11815</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265860"&gt;@BrahmanandaRao&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;using datastep not in proc step&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Provide a valid reason.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Saying that data step must be used is like saying you have to use a teaspoon to dig a ditch instead of backhoe or trencher or other machine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proper tool for the task.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or since you starting with a spreadsheet use the spreadsheet tools to sort the data before import. I notice that the data is sorted by decreasing population already. So why do you even think you need to sort the data????&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2019 14:17:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/variable-sort-using-datastep/m-p/569437#M11815</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-06-27T14:17:22Z</dc:date>
    </item>
    <item>
      <title>Re: variable sort using datastep</title>
      <link>https://communities.sas.com/t5/New-SAS-User/variable-sort-using-datastep/m-p/569445#M11819</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265860"&gt;@BrahmanandaRao&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;using datastep not in proc step&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Provide a valid reason.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;By example, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265860"&gt;@BrahmanandaRao&lt;/a&gt;&amp;nbsp;seems to have provided a valid reason for doing this in PROC SORT. Had he done that, there would be no errors in his code, it would work the first time, and he'd be done and moved on to whatever is next over 2 hours ago.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2019 14:28:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/variable-sort-using-datastep/m-p/569445#M11819</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-06-27T14:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: variable sort using datastep</title>
      <link>https://communities.sas.com/t5/New-SAS-User/variable-sort-using-datastep/m-p/569490#M11823</link>
      <description>&lt;P&gt;Maxim 14.&lt;/P&gt;
&lt;P&gt;Use proc sort. If you can run data steps, you can run proc sort, it is part of Base SAS.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2019 15:21:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/variable-sort-using-datastep/m-p/569490#M11823</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-06-27T15:21:07Z</dc:date>
    </item>
    <item>
      <title>Re: variable sort using datastep</title>
      <link>https://communities.sas.com/t5/New-SAS-User/variable-sort-using-datastep/m-p/569512#M11826</link>
      <description>&lt;P&gt;Maximum 14 means&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2019 16:06:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/variable-sort-using-datastep/m-p/569512#M11826</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2019-06-27T16:06:34Z</dc:date>
    </item>
    <item>
      <title>Re: variable sort using datastep</title>
      <link>https://communities.sas.com/t5/New-SAS-User/variable-sort-using-datastep/m-p/569519#M11827</link>
      <description>&lt;P&gt;Read the first link of my footnotes&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="4"&gt;&lt;STRONG&gt;USE THE RIGHT TOOL.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2019 16:12:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/variable-sort-using-datastep/m-p/569519#M11827</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-06-27T16:12:07Z</dc:date>
    </item>
  </channel>
</rss>

