Well, to my mind, if you need to use database specific functionality like that, then code on the database. Otherwise extract the data to SAS and process the data there. You will find partitioning data is pretty easy in SAS - its a different way of thinking of the data. So something that could be quite tricky in SQL can be done in one procedure in SAS. No point programming another system from within SAS.
One simple example, SQL does not have logical observation order, so lagging data would mean sub-querys or joins, but in SAS you can just lag to previous value. Obs can be identifed just by _n_ as another example, which SQL can't do.
... View more