LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (August 2006, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 2 Aug 2006 12:32:46 -0400
Reply-To:     "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM>
Subject:      Re: How to tell if a dataset has been sorted

On Wed, 2 Aug 2006 08:12:23 -0700, Ken Karan <posible88-sswug@YAHOO.COM> wrote:

>The problem with the sortedby indicator is it is often not preserved once a >dataset has been "re-set" into another data step.

It's also possible for it to be present but incorrect, since it can be manipulated via PROC DATASETS.

>A more resource intensive >method but more sure fire method would be: > >data; > infile datalines; > input var1 @@; > datalines; >1 3 2 >; > run; > >data _null_; > set _last_; > old1 = lag(var1); > if var1 < old1 then do; > put 'Note: Input dataset data1 not sorted by var1. Halting datastep.'; > stop; > end; > run; > >If you had more than one sort variable, you could concatenate the sort >variables into one "key" and check that in the lag function.

Ken may be working too hard. BY processing will do the same thing. For example:

892 data _null_; 893 set sashelp.class; 894 by age; 895 run;

ERROR: BY variables are not properly sorted on data set SASHELP.CLASS. Name=Alfred Sex=M Age=14 Height=69 Weight=112.5 FIRST.Age=1 LAST.Age=1 _ERROR_=1 _N_=1 NOTE: The SAS System stopped processing this step because of errors. NOTE: There were 2 observations read from the data set SASHELP.CLASS.

However, the BY spec can also be satisfied with an index. It seems to me that Ken's approach is one way to prevent getting a false confirmation that way.

> >Good luck, > >Ken

Back to: Top of message | Previous page | Main SAS-L page