PROC SQL by Example- Using SQL within SAS.pdf

(2247 KB) Pobierz
“This book has some great tips I will be putting to use! I’ve been programming with SAS
and SQL for years, and this book is a really informative resource. I think learning by
example is a thorough and efficient way to understand SAS techniques. The book has
examples that you can pick up and use right away. I particularly enjoyed the comparisons
between the Base SAS code and the PROC SQL code. It is a great bridge for SAS
programmers to easily pick up this new language.”
Candice Miller
Research Programmer, RAND Corporation
“PROC SQL by Example: Using SQL within SAS
is an excellent introduction and
reference manual for users looking to learn or brush up on their PROC SQL skills. The
book does a great job of comparing SAS procedures to their PROC SQL counterparts.
Using multiple examples, the book enables readers to easily follow along and grasp the
knowledge needed to effectively enhance their SAS skills to tackle complex and new
problems that might have been overwhelming before.
“Overall,
PROC SQL by Example
is a great introduction to the topic and will benefit
those looking to make the jump forward.”
Faisal Dosani
Senior Information Analyst
“PROC SQL by Example: Using SQL within SAS
will appeal especially to those who
have some experience with SAS DATA step programming and procedures, and who now
have an interest in moving into SQL database programming. The author illustrates how
SAS DATA steps and procedures translate into SQL syntax. More important, he also
helps the reader understand how SQL programs embody logical constructs as opposed to
procedural steps. Discussions of DATA step and SAS SQL programs build on actual
programs that a reader can execute and modify. Perhaps for this reason, the text and
examples achieve a level of precision and integrity that one rarely finds in a ‘how to by
example’ text. Notable extra features include discussions of SAS SQL options, set
operators, using PROC SQL as a report generator (as an alternative to PROC REPORT or
PROC TABULATE), SAS MACRO scripting, ‘pivoting’ data structures using PROC
TRANSPOSE, and data set persistence versus replacement.
“This book takes the programming cookbook genre to a new level of excellence.”
Sigurd W. Hermansen
Westat
PROC SQL
by Example
Using SQL within SAS
®
Howard Schreier
The correct bibliographic citation for this manual is as follows: Schreier, Howard. 2008.
PROC SQL by
Example: Using SQL within SAS
®
.
Cary, NC: SAS Institute Inc.
PROC SQL by Example: Using SQL within SAS
®
Copyright © 2008, SAS Institute Inc., Cary, NC, USA
ISBN 978-1-59994-297-1
All rights reserved. Produced in the United States of America.
For a hard-copy book:
No part of this publication may be reproduced, stored in a retrieval system, or
transmitted, in any form or by any means, electronic, mechanical, photocopying, or otherwise, without the
prior written permission of the publisher, SAS Institute Inc.
For a Web download or e-book:
Your use of this publication shall be governed by the terms established by
the vendor at the time you acquire this publication.
U.S. Government Restricted Rights Notice:
Use, duplication, or disclosure of this software and related
documentation by the U.S. government is subject to the Agreement with SAS Institute and the restrictions set
forth in FAR 52.227-19, Commercial Computer Software-Restricted Rights (June 1987).
SAS Institute Inc., SAS Campus Drive, Cary, North Carolina 27513.
1st printing, September 2008
SAS
®
Publishing provides a complete selection of books and electronic products to help customers use SAS
software to its fullest potential. For more information about our e-books, e-learning products, CDs, and hard-
copy books, visit the SAS Publishing Web site at
support.sas.com/publishing
or call 1-800-727-3228.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS
Institute Inc. in the USA and other countries. ® indicates USA registration.
Other brand and product names are registered trademarks or trademarks of their respective companies.
®
Contents
Acknowledgments vii
Chapter 1 Introduction
1
1.1 More about SQL 2
1.2 More about This Book 5
Chapter 2 Basic Building Blocks
11
2.1 The Simplest SELECT Statement 13
2.2 A More Selective SELECT 15
2.3 Storing Results 16
2.4 Column Subsets 17
2.5 New Columns 19
2.6 Aggregation 20
2.7 Conditionality 26
2.8 Filtering 28
2.9 Reordering Rows 32
2.10 Elimination of Duplicates 33
2.11 Summary 35
Chapter 3 More Building Blocks
3.1
3.2
3.3
3.4
37
Combining Summary Statistics with Original Detail 38
Summary Statistics Based on Distinct Values 43
Preprocessing the Source with Inline Views 46
Summary 51
Zgłoś jeśli naruszono regulamin