Limiting/Filtering Results in SAS

Posted on May 28, 2015 in Computer Science

Things under legendu.net/outdated are outdated technologies that the author does not plan to update any more. Please look for better alternatives.

** Things under legendu.net/outdated are outdated technologies that the author does not plan to update any more. Please look for better alternatives. **

In the data step you can use the hidden variable _n_ to select records based on observation id.

In proc sql, you can use the outobs option. In other procedures, you can use firstobs together with obs to limit records based observation id. Again, this is ugly as you have to much to remember when using SAS.

proc sql;
    select *
    from sasHelp.cars
    where monotonic() <= 10;
quit;

The monotonic function is similar to the row_number function in Oracle SQL.

proc sql outobs=10;
    select
        *
    from 
        ia.ia_lgd_final_macro_mdl_v2
    ;
quit;

For other steps, you can use firstObs and obs to limit the number of observations.

proc print data=s (obs=5);
run;