You can use the SQLOBS automatic variable.
SQLOBS
contains the number of rows that were processed by an SQL procedure statement. For example, the SQLOBS macro variable contains the number of rows that were formatted and displayed in SAS output by a SELECT statement or the number of rows that were deleted by a DELETE statement.
When the NOPRINT option is specified, the value of the SQLOBS macro variable depends on whether an output table, single macro variable, macro variable list, or macro variable range is created:
If no output table, macro variable list, or macro variable range is created, then SQLOBS contains the value 1.
If an output table is created, then SQLOBS contains the number of rows in the output table.
If a single macro variable is created, then SQLOBS contains the value 1.
If a macro variable list or macro variable range is created, then SQLOBS contains the number of rows that are processed to create the macro variable list or range.
If an SQL view is created, then SQLOBS contains the value 0.
Note: The SQLOBS automatic macro variable is assigned a value after the SQL SELECT statement executes.