Go Back   Rhinocerus > Newsgroup > Newsgroup comp.soft-sys.sas

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 04-02-2007, 12:15 AM
Sigurd Hermansen
Guest
 
Posts: n/a
Default Re: Sorted views (was: Sort order change from Mainframe to

Robert:
Experts in the database field advise against relying on ordering of the =
yield of views. Date cites an example. An ordering by one attribute does =
not have one possible result for any one source dataset. As a result, =
tests of queries may succeed in one context, given an ordered view, but =
fail in another context given that same view. More generally, since SQL =
does not require pre-ordering of tuples, nor guarantee that processing =
will maintain a sort order, it usually makes more sense to order data =
within data display procedures than in a view. I can think of =
exceptional situations, but each situation would have to be considered =
carefully.
S

________________________________

From: owner-sas-l@listserv.uga.edu on behalf of Robert Bardos
Sent: Sun 4/1/2007 3:36 AM
To: SAS-L List
Subject: Sorted views (was: Sort order change from Mainframe to Windows)



Howard Schreier's post in the "Sort order change from Mainframe to
Windows" thread contains a very interesting aspect regarding views
and sort:

> Howard Schreier


<some lines snipped ... RB>

> Boston, with an upper case "B", would appear before
> "atlanta" in a simple sort.
>
> So create a view with "hidden" sort keys:
>
> proc sql;
> create view temp_in_report_order as
> select *
> from temp
> order by anydigit(substr(region,1,1) )
> , upcase(region)
> , region;
> quit;
>
> The first ORDER key pushes the digit strings to the
> bottom. The second
> ignores case.
>
> The view looks like this:
>
> region runame
>
> atlanta atlanta
> Boston Boston
> dallas dallas
> newyork newyork
> 100 100
> 500 500
>
> Then code:
>
> proc print data=3Dtemp_in_report_order;
> by region notsorted;
> run;
>


Learned something new today (though I could/should have known it).
Quite often I refrained from using views since "you can't create
sorted views" (meaning: "you can't sort views onto themselves" or
even "you can't create a view as output from proc sort"). I was
wrong: while I can't use datastep views for that purpose I can
very well use SQL views for that purpose!

Knowledge beats experiments here (as most everybody who tried to
develop fool-proof code knows, the universe will win this contest,
so even intensive experimenting may miss exactly the one case
where my assumptions go wrong), so I ask this august group: would
you consider the use of sorted SQL views safe for production jobs
("jobs" in the sense of "batch SAS executions") ??

TIA for your thoughts

Robert Bardos
Ansys AG, Zurich, Switzerland
Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorted views (was: Sort order change from Mainframe to Windows) Robert Bardos Newsgroup comp.soft-sys.sas 1 04-01-2007 05:18 PM
Re: Sort order change from Mainframe to Windows nospam@HOWLES.COM (Howard Schreier Newsgroup comp.soft-sys.sas 0 03-31-2007 09:29 PM
Re: Sort order change from Mainframe to Windows toby dunn Newsgroup comp.soft-sys.sas 0 03-30-2007 01:23 PM
Sort order change from Mainframe to Windows Narasimhaiah Devadula Newsgroup comp.soft-sys.sas 1 03-30-2007 10:24 AM
Re: Order of records returned by SELECTs without ORDER Bys (was : Charles Harbour Newsgroup comp.soft-sys.sas 0 07-13-2005 08:59 PM



All times are GMT. The time now is 05:06 AM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.