SQL-statement to find lowest observation in dataset

The SAS SQL-statement below will create a dataset containing all information for the observation with the lowest age in the dataset SASHELP.CLASS.

proc sql;
     create table CLASS as
           select     *
           from SASHELP.CLASS
           group by AGE
           having AGE=min(AGE)
     ;
quit;

The syntax for the SAS SQL-statement is showed below.

proc sql;
     create table <DESTINATION TABLE> as
           select     *
           from <SOURCE TABLE>
           group by <COLUMN TO SEARCH>
           having <COLUMN TO SEARCH>=<FUNCTION>(<COLUMN TO SEARCH>)
     ;
quit;

As you see the <FUNCTION> doesn’t have to be min (minimum), it can be any function working on the type of <COLUMN TO SEARCH> – numeric or char.

Leave a Reply

Your email address will not be published. Required fields are marked *