BookmarkSubscribeRSS Feed

To traverse a dataset from its last record to its first, let the user provide a dataset option ReversedOrder="Y"|"YES".

 

Let this work with SET, MERGE, UPDATE statements, and for any procedures that read datasets, applying only when the dataset is being read.

 

Default ReversedOrder="NO".

 

I have no idea how feasible this is, but I've frequently encountered situations where I would want to do this.  It feels mathematically unnecessary to have to resort a dataset in descending order just to -- or to sort datasets in descending order, and provide an index in ascending order just to -- have this capability.

 

I would love to know why this couldn't be done, but not as much as having the ability to do it.

6 Comments
mkeintz
PROC Star

The data storage on disk is in a bunch of physical blocks of data, which are not necessarily physically contiguous   So a pointer is needed to tell SAS (to tell the op-system really) where the next block is (this is when you are sequentially reading the data, without the benefit of an index).  If the pointer to block number i+1 is in located in block i, then you have a way to go forward, but not backward from block i+1 to block i.   Now, I don't know how the file system actually locates such information (and it likely would be operating-system dependent).  But unless those block pointers are in some sort of header record (analogous to an index file), I don't see how your wish can be fulfilled.

 

But what a great thing it would be.

 

PhilC
Rhodochrosite | Level 12

@mkeintz 

 

Views can be implemented too. See Stack Overflow: SAS: can I make sas process observations backwards.

 

A vote wouldn't hurt, if they could do it or would do it. 🙂

 

mkeintz
PROC Star

@PhilC 

 

Ah yes, using point= can support reading a dataset backward, but I suspect it will be far  slower, since it is emulating a direct-access mode instead of sequential.  I.e. it has to spend time calculating which block # (and which within-block record) has record number i.

 

But since the "point=" technique does actually work, I guess it implies that there is (on every SAS platform) some sort of file system header information that has the physical location of all the data blocks. So maybe that can be converted into a reverse sequential process, without needing iterative resolution of the location of each "point=" record number.

 

Anyhow, you have my vote.

 

Quentin
Super User

Neat idea.  Would take some time for me to get used to thinking through by-group processing and first. last. if it were reading from last record, but I like it.  There would be a lot of documentation to re-write. : )

ChrisNZ
Tourmaline | Level 20
@ChrisHemedinger No way to upvote from a mobile. Or to use @ it seems.
ChrisNZ
Tourmaline | Level 20
Oh. The @ worked after all.