Chapter Contents

Previous

Next
The SQL Procedure

Example 8: Creating a View from a Query's Result


Procedure features:
CREATE VIEW statement
GROUP BY clause
SELECT clause
COUNT function
HAVING clause
Other features:
AVG summary function
data set option
PW=
Tables: PROCLIB.PAYROLL, PROCLIB.JOBS

This example creates the PROC SQL view PROCLIB.JOBS from the result of a query-expression.



Input Table
PROCLIB.PAYROLL (Partial Listing) [HTML Output]
 [Listing Output]


Program

libname proclib 'SAS-data-library';
options nodate pageno=1 linesize=80 pagesize=60;
 Note about code
proc sql;
   create view proclib.jobs(pw=red) as
 Note about code
      select Jobcode,
             count(jobcode) as number label='Number',
 Note about code
             avg(int((today()-birth)/365.25)) as avgage
                format=2. label='Average Age',
             avg(salary) as avgsal
                format=dollar8. label='Average Salary'
 Note about code
      from payroll


 Note about code
      group by jobcode
      having avgage ge 30;




 Note about code
   title 'Current Summary Information for Each Job Category';
   title2 'Average Age Greater Than Or Equal to 30';
   select * from proclib.jobs(pw=red);


Output
[HTML Output]  [Listing Output]


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.