PROC SQL can perform some of
the operations that are provided by the DATA step and the PRINT, SORT,
and SUMMARY procedures. The following query displays the total population
of all the large countries (countries with population greater than
1 million) on each continent.
proc sql;
title 'Population of Large Countries Grouped by Continent';
select Continent, sum(Population) as TotPop format=comma15.
from sql.countries
where Population gt 1000000
group by Continent
order by TotPop;
quit;
Here is a SAS program
that produces the same result.
title 'Large Countries Grouped by Continent';
proc summary data=sql.countries;
where Population > 1000000;
class Continent;
var Population;
output out=sumPop sum=TotPop;
run;
proc sort data=SumPop;
by totPop;
run;
proc print data=SumPop noobs;
var Continent TotPop;
format TotPop comma15.;
where _type_=1;
run;
This example shows that
PROC SQL can achieve the same results as Base SAS software but often
with fewer and shorter statements. The SELECT statement that is shown
in this example performs summation, grouping, sorting, and row selection.
It also displays the query's results without the PRINT procedure.
PROC SQL executes without
using the RUN statement. After you invoke PROC SQL you can submit
additional SQL procedure statements without submitting the PROC statement
again. Use the QUIT statement to terminate the procedure.