Extract the first n records from a SAS dataset using PROC SQL

If you are using SAS and have a large dataset where you only want ot analyze the first 100 rows, you can create a new sas dataset consisting of those first 100 observations.

Below is the PROC SQL statement that will accomplish that for you.

PROC SQL outobs=100;

create table library.data_set2 as

select *

from library.data_set1;

QUIT;

 

The key to this is the outobs=100.  This statement following PROC SQL on the first line specifies that you only want the first 100 rows.  Your log will display a message like "WARNING: Statement terminated early due to OUTOBS=100 option".  There is no need for concern since that is what we wanted to do.  We want to terminate the job early, that is, after 100 observations have been written to our new dataset.