Proc SQL
does not implement current modern clauses such a LIMIT
, OFFSET
, FETCH
, nor does it have partitioning functions you may be familiar with.
That said, you can not row limit the output of a sorted sub select or view, however, you can limit the output to a table using the OUTOBS
option.
This sample creates two tables, each corresponding to a sub-select limiting 10 rows of a sorted result set. The option is reset prior to unioning them.
proc sql;
reset outobs=10;
create table have_ss1 as
select distinct msrp as msrp_1
from sashelp.cars
group by model
;
create table have_ss2 as
select distinct msrp as msrp_2
from sashelp.cars
group by model
;
reset outobs=&sysmaxlong;
create table want as
select * from have_ss1
outer union
select * from have_ss2
;
The SAS log window will show informative warnings, such as:
WARNING: A GROUP BY clause has been transformed into an ORDER BY clause because neither the
SELECT clause nor the optional HAVING clause of the associated table-expression
referenced a summary function.
WARNING: The query as specified involves ordering by an item that doesn't appear in its SELECT
clause. Since you are ordering the output of a SELECT DISTINCT it may appear that some
duplicates have not been eliminated.
WARNING: Statement terminated early due to OUTOBS=10 option.