<?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: BY variable not properly sorted? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/BY-variable-not-properly-sorted/m-p/23344#M3871</link>
    <description>It appears to be a failure in proc sort.  Here is the offending observation post sort:&lt;BR /&gt;
                                          EI020510400011934&lt;BR /&gt;
                                          EI020510400011934&lt;BR /&gt;
                                          EI020%10400011935&lt;BR /&gt;
                                          EI020510400011935&lt;BR /&gt;
&lt;BR /&gt;
The proper sort order should be:&lt;BR /&gt;
                                          EI020%10400011935&lt;BR /&gt;
                                          EI020510400011934&lt;BR /&gt;
                                          EI020510400011934&lt;BR /&gt;
                                          EI020510400011935&lt;BR /&gt;
&lt;BR /&gt;
If I sort just the subset the order is correct however when I sort the entire data set, it comes out incorrect.</description>
    <pubDate>Thu, 28 Oct 2010 20:34:56 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2010-10-28T20:34:56Z</dc:date>
    <item>
      <title>BY variable not properly sorted?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/BY-variable-not-properly-sorted/m-p/23339#M3866</link>
      <description>Hi,&lt;BR /&gt;
I have not used SAS is a while so I may be missing something obvious here.  I've tried a few approaches (dropping and recreating data sets, resorting etc) however continue to get this error.  &lt;BR /&gt;
&lt;BR /&gt;
232&lt;BR /&gt;
233  proc sort data=dosdist;&lt;BR /&gt;
234   by claim_number;&lt;BR /&gt;
235   run;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: There were 17644882 observations read from the data set WORK.DOSDIST.&lt;BR /&gt;
NOTE: The data set WORK.DOSDIST has 17644882 observations and 4 variables.&lt;BR /&gt;
NOTE: PROCEDURE SORT used (Total process time):&lt;BR /&gt;
      real time           1:43.34&lt;BR /&gt;
      cpu time            21.84 seconds&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
236&lt;BR /&gt;
237  data diags2;&lt;BR /&gt;
238    merge dosdist(in=a)&lt;BR /&gt;
239           diags(in=b);&lt;BR /&gt;
240      by claim_number;&lt;BR /&gt;
241      if b;&lt;BR /&gt;
242      run;&lt;BR /&gt;
&lt;BR /&gt;
ERROR: BY variables are not properly sorted on data set WORK.DOSDIST.&lt;BR /&gt;
a=1 b=1 claim_number=EP090810701843592 &lt;BR /&gt;
FIRST.claim_number=0 LAST.claim_number=0 _ERROR_=1 _N_=6554391&lt;BR /&gt;
NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;
NOTE: There were 6554389 observations read from the data set WORK.DOSDIST.&lt;BR /&gt;
NOTE: There were 1984547 observations read from the data set WORK.DIAGS.&lt;BR /&gt;
WARNING: The data set WORK.DIAGS2 may be incomplete.  When this step was stopped there were 6554388&lt;BR /&gt;
         observations and 47 variables.&lt;BR /&gt;
WARNING: Data set WORK.DIAGS2 was not replaced because this step was stopped.&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           3:44.86&lt;BR /&gt;
      cpu time            18.95 seconds</description>
      <pubDate>Tue, 26 Oct 2010 23:07:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/BY-variable-not-properly-sorted/m-p/23339#M3866</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-10-26T23:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: BY variable not properly sorted?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/BY-variable-not-properly-sorted/m-p/23340#M3867</link>
      <description>I was successful using SQL</description>
      <pubDate>Tue, 26 Oct 2010 23:11:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/BY-variable-not-properly-sorted/m-p/23340#M3867</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-10-26T23:11:28Z</dc:date>
    </item>
    <item>
      <title>Re: BY variable not properly sorted?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/BY-variable-not-properly-sorted/m-p/23341#M3868</link>
      <description>I do not see anything in the code specifically, but do you know that WORK.DIAGS is sorted correctly?  Do you know that the attributes of CLAIM_NUMBER, especially the length, are the same for both data sets?</description>
      <pubDate>Wed, 27 Oct 2010 04:49:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/BY-variable-not-properly-sorted/m-p/23341#M3868</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2010-10-27T04:49:31Z</dc:date>
    </item>
    <item>
      <title>Re: BY variable not properly sorted?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/BY-variable-not-properly-sorted/m-p/23342#M3869</link>
      <description>Thanks ArtC (the hammer and nails guy?).   I'm running this on a workstation as I do not have a server license.  &lt;BR /&gt;
&lt;BR /&gt;
Here is what I have (log included):&lt;BR /&gt;
                                      The CONTENTS Procedure&lt;BR /&gt;
&lt;BR /&gt;
       Data Set Name        WORK.DIAGS                       Observations          7258643&lt;BR /&gt;
&lt;BR /&gt;
                              1    claim_number           Char     18&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
                                        Sort Information&lt;BR /&gt;
&lt;BR /&gt;
                                   Sortedby       claim_number&lt;BR /&gt;
                                   Validated      YES&lt;BR /&gt;
                                   Character Set  ANSI&lt;BR /&gt;
&lt;BR /&gt;
                                      The CONTENTS Procedure&lt;BR /&gt;
&lt;BR /&gt;
       Data Set Name        WORK.DOS                         Observations          17644882&lt;BR /&gt;
&lt;BR /&gt;
                                1    claim_number     Char     18&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
                                        Sort Information&lt;BR /&gt;
&lt;BR /&gt;
                                   Sortedby       claim_number&lt;BR /&gt;
                                   Validated      YES&lt;BR /&gt;
                                   Character Set  ANSI&lt;BR /&gt;
                                   Sort Option    NODUPREC&lt;BR /&gt;
404  proc sort data=diags;&lt;BR /&gt;
405    by claim_number;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: Input data set is already sorted, no sorting done.&lt;BR /&gt;
NOTE: PROCEDURE SORT used (Total process time):&lt;BR /&gt;
      real time           0.04 seconds&lt;BR /&gt;
      cpu time            0.00 seconds&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
406  proc sort data=dos;&lt;BR /&gt;
407    by claim_number;&lt;BR /&gt;
408&lt;BR /&gt;
&lt;BR /&gt;
NOTE: Input data set is already sorted, no sorting done.&lt;BR /&gt;
NOTE: PROCEDURE SORT used (Total process time):&lt;BR /&gt;
      real time           0.03 seconds&lt;BR /&gt;
      cpu time            0.00 seconds&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
409  data diags2;&lt;BR /&gt;
410    merge diags dos;&lt;BR /&gt;
411    by claim_number;&lt;BR /&gt;
412    run;&lt;BR /&gt;
&lt;BR /&gt;
ERROR: BY variables are not properly sorted on data set WORK.DIAGS.&lt;BR /&gt;
 FIRST.claim_number=1 LAST.claim_number=1 _ERROR_=1 _N_=5434037&lt;BR /&gt;
NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;
NOTE: There were 1474189 observations read from the data set WORK.DIAGS.&lt;BR /&gt;
NOTE: There were 5434036 observations read from the data set WORK.DOS.&lt;BR /&gt;
WARNING: The data set WORK.DIAGS2 may be incomplete.  When this step was stopped there were&lt;BR /&gt;
         5434036 observations and 50 variables.&lt;BR /&gt;
WARNING: Data set WORK.DIAGS2 was not replaced because this step was stopped.</description>
      <pubDate>Thu, 28 Oct 2010 01:00:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/BY-variable-not-properly-sorted/m-p/23342#M3869</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-10-28T01:00:33Z</dc:date>
    </item>
    <item>
      <title>Re: BY variable not properly sorted?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/BY-variable-not-properly-sorted/m-p/23343#M3870</link>
      <description>I believe that the OP has a "variable length" compatibility issue which is contributing to the error condition.  Suggest using PROC CONTENTS on the two input files being merged.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 28 Oct 2010 02:19:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/BY-variable-not-properly-sorted/m-p/23343#M3870</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-10-28T02:19:51Z</dc:date>
    </item>
    <item>
      <title>Re: BY variable not properly sorted?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/BY-variable-not-properly-sorted/m-p/23344#M3871</link>
      <description>It appears to be a failure in proc sort.  Here is the offending observation post sort:&lt;BR /&gt;
                                          EI020510400011934&lt;BR /&gt;
                                          EI020510400011934&lt;BR /&gt;
                                          EI020%10400011935&lt;BR /&gt;
                                          EI020510400011935&lt;BR /&gt;
&lt;BR /&gt;
The proper sort order should be:&lt;BR /&gt;
                                          EI020%10400011935&lt;BR /&gt;
                                          EI020510400011934&lt;BR /&gt;
                                          EI020510400011934&lt;BR /&gt;
                                          EI020510400011935&lt;BR /&gt;
&lt;BR /&gt;
If I sort just the subset the order is correct however when I sort the entire data set, it comes out incorrect.</description>
      <pubDate>Thu, 28 Oct 2010 20:34:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/BY-variable-not-properly-sorted/m-p/23344#M3871</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-10-28T20:34:56Z</dc:date>
    </item>
    <item>
      <title>Re: BY variable not properly sorted?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/BY-variable-not-properly-sorted/m-p/23345#M3872</link>
      <description>It also appears that the special characters are not on the input data file and the values are being corrupted by proc sort.  22 million obs, is this just to big?</description>
      <pubDate>Thu, 28 Oct 2010 20:58:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/BY-variable-not-properly-sorted/m-p/23345#M3872</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-10-28T20:58:46Z</dc:date>
    </item>
    <item>
      <title>Re: BY variable not properly sorted?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/BY-variable-not-properly-sorted/m-p/23346#M3873</link>
      <description>Not likely - suggest you open a Support track to investigate the condition (link at bottom of page).&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 28 Oct 2010 21:00:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/BY-variable-not-properly-sorted/m-p/23346#M3873</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-10-28T21:00:48Z</dc:date>
    </item>
    <item>
      <title>Re: BY variable not properly sorted?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/BY-variable-not-properly-sorted/m-p/23347#M3874</link>
      <description>Sometimes those 'special characters' can be introduced in non-standard ways.  To check the size  of data issue, which I agree with Scott is unlikely to be the culprit, try a FIRSTOBS and LASTOBS or OBS system option to isolate a few hundred obs on either side and see if the problem goes away.  it is more likely that the special character has already been introduced.</description>
      <pubDate>Fri, 29 Oct 2010 19:29:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/BY-variable-not-properly-sorted/m-p/23347#M3874</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2010-10-29T19:29:21Z</dc:date>
    </item>
    <item>
      <title>Re: BY variable not properly sorted?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/BY-variable-not-properly-sorted/m-p/23348#M3875</link>
      <description>I ran several times, not only are special characters showing up randomly, they are occurring on different observations and not every time (1 or 2 out of 20+ million.  SAS tech support thinks it may be an issue with the disk drive or bad memory as I am able to demonstrate in the log that the characters are not on the input file or in the first dataset created but show up right after the sort.  I cannot reproduce every time.  I am also occasionally losing the end of record marker causing the output data file having data from the following record in the last field on the previous record (once again, one record out of several million, occurring occasionally).   Thanks for responding though.</description>
      <pubDate>Sat, 30 Oct 2010 15:25:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/BY-variable-not-properly-sorted/m-p/23348#M3875</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-10-30T15:25:01Z</dc:date>
    </item>
    <item>
      <title>Re: BY variable not properly sorted?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/BY-variable-not-properly-sorted/m-p/339493#M77444</link>
      <description>&lt;P&gt;I am not an expert but maybe you should have PROC SORT command&amp;nbsp;for both data which you want to merge. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2017 01:10:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/BY-variable-not-properly-sorted/m-p/339493#M77444</guid>
      <dc:creator>hanish</dc:creator>
      <dc:date>2017-03-09T01:10:51Z</dc:date>
    </item>
  </channel>
</rss>

