why ONLY SQL?
There must be some reason you could explain!
Because SQL does not acknowledge row-order, it is unable to take advantage of that information, which is available to a data step reading a SAS table.
Perhaps your undeclared reason might point to alternative approaches like dbms-specific opportunities.
Would you like to explain why you can't use a data step for this (it makes reading SAS data in reverse, easy).