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 (March 2004, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 9 Mar 2004 04:34:14 -0600
Reply-To:     Kevin Myers <KevinMyers@AUSTIN.RR.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Kevin Myers <KevinMyers@AUSTIN.RR.COM>
Organization: Posted via Supernews, http://www.supernews.com
Subject:      Re: SORTEDBY after MERGE

"Robert Burbidge" <RBurbidge@PHD.CO.UK> wrote in message news:F83CD98B6E0ABB4B8B56E880DF92F7550EAA87@phd-exch1.phd.int... > Hi all, > > Could someone explain why after merging two sorted tables, the result is not sorted?

As explained further below, the result *DOES* remain sorted. The resulting output data set simply doesn't have the sorted by attribute set. That does *NOT* mean that the data set is not sorted. It simply means that SAS no longer knows whether it is sorted or not.

> > <sas> > data test1; > infile datalines; > input ID; > datalines; > 2 > 1 > 4 > 5 > 7 > 3 > ; > data test2; > infile datalines; > input ID; > datalines; > 3 > 0 > -2 > 0.1 > 7 > . > ; > proc sort data = test1; by ID; > proc sort data = test2; by ID; > data test3; merge test1 test2; by ID; > proc contents data = test3; run; > </sas> > > There's an interesting (and divergent) thread pertaining to this in the archives: > http://listserv.uga.edu/cgi-bin/wa?A2=ind0110B&L=sas-l&D=0&P=15646 > > It seems that any DATA step will copy the table but not the SORTEDBY, even if the sort key is not changed (the docs suggest that the SORTEDBY is only overwritten if the sort key is manipulated in some way.) E.g.: > > <sas> > data test4; set test1; /* test1 is sorted */ > proc contents data = test4; run; /* test4 isn't! */ > </sas>

Incorrect. Data set test4 *IS* sorted. However, it simply doesn't have the sorted by attribute set. Why not? Because 1) SAS doesn't try to figure out all the kinds of possible manipulations in a data step that could have affected the order of the output observations relative to the values of it s variables, and 2) because data set test4 is a completely *different* data set from test1 as far as SAS is concerned. SAS does not "pass" the value of the sorted by attribute from one data set to another, unless perhaps you are doing something like a simple proc copy.

> > What are the pitfalls of using the following? > > <sas> > data test3 (sortedby = ID); merge test1 test2; by ID; > </sas>

There are no pitfalls of doing this as long as you can be *certain* that you haven't done anything to get the ID values out of order, which you haven't in this case.

> > [Release 8.02, Windows 5.1 (XP)] > > Thanks+rgds, > > Robert > > > > > **************************************************************************** ******* > Privileged/Confidential Information may be contained in this message. > If you are not the addressee indicated in the message (or responsible > for the delivery of the message to such person), you may not copy > or deliver this message to anyone. > In such case, you should destroy this message and kindly notify the > sender by reply Email. Please advise immediately if you or your employer > does not consent to Internet Email for messages of this kind. > Opinions, conclusions and other information in this message that do not > relate to the official business of PHD Limited or its > Group/Associated Companies shall be understood as neither given nor > endorsed by them. > PHD Limited > Registered in England. > Registered Number: 2423952 > Registered Office: The Telephone Exchange, 5 North Crescent, Chenies Street, London, WC1E 7PH > Telephone: 020 7446 0555 > Fax: 020 7446 7100 > E-Mail: postmaster@phd.co.uk > **************************************************************************** *******


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