




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





























































































®
The correct bibliographic citation for this manual is as follows: SAS Institute Inc.
Step-by-Step Programming with Base SAS®^ Software Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. ISBN 978-1-58025-791- 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. February 2007 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/pubs 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.
1
Introduction to the SAS System
Chapter 1......... .What Is the SAS System?^^3
2
4 Components of Base SAS Software Chapter 1
At the core of the SAS System is Base SAS software which is the software product that you will learn to use in this documentation. This section presents an overview of Base SAS. It introduces the capabilities of Base SAS, addresses methods of running SAS, and outlines various types of output.
Components of Base SAS Software
Overview of Base SAS Software Base SAS software contains the following: a data management facility a programming language data analysis and reporting utilities Learning to use Base SAS enables you to work with these features of SAS. It also prepares you to learn other SAS products, because all SAS products follow the same basic rules.
Data Management Facility SAS organizes data into a rectangular form or table that is called a SAS data set. The following figure shows a SAS data set. The data describes participants in a 16-week weight program at a health and fitness club. The data for each participant includes an identification number, name, team name, and weight (in U.S. pounds) at the beginning and end of the program.
Figure 1.1 Rectangular Form of a SAS Data Set
IdNumber
1023
Name Team StartWeight
variable
data value
EndWeight
David Shaw
Amelia Serrano
Alan Nance
Ravi Sinha
Ashley McKnight
red
yellow
red
yellow
red
data value
observation
In a SAS data set, each row represents information about an individual entity and is called an observation. Each column represents the same type of information and is called a variable. Each separate piece of information is a data value. In a SAS data set,
What Is the SAS System? Programming Language 5
an observation contains all the data values for an entity; a variable contains the same type of data value for all entities. To build a SAS data set with Base SAS, you write a program that uses statements in the SAS programming language. A SAS program that begins with a DATA statement and typically creates a SAS data set or a report is called a DATA step. The following SAS program creates a SAS data set named WEIGHT_CLUB from the health club data:
data weight_club; u input IdNumber 1-4 Name $ 6-24 Team $ StartWeight EndWeight; v Loss=StartWeight-EndWeight; w datalines; x 1023 David Shaw red 189 165 y 1049 Amelia Serrano yellow 145 124 y 1219 Alan Nance red 210 192 y 1246 Ravi Sinha yellow 194 177 y 1078 Ashley McKnight red 127 118 y ; U
run;
The following list corresponds to the numbered items in the preceding program: u The DATA statement tells SAS to begin building a SAS data set named WEIGHT_CLUB. v The INPUT statement identifies the fields to be read from the input data and names the SAS variables to be created from them (IdNumber, Name, Team, StartWeight, and EndWeight). w The third statement is an assignment statement. It calculates the weight each person lost and assigns the result to a new variable, Loss. x The DATALINES statement indicates that data lines follow. y The data lines follow the DATALINES statement. This approach to processing raw data is useful when you have only a few lines of data. (Later sections show ways to access larger amounts of data that are stored in files.) U The semicolon signals the end of the raw data, and is a step boundary. It tells SAS that the preceding statements are ready for execution.
Note: By default, the data set WEIGHT_CLUB is temporary; that is, it exists only for the current job or session. For information about how to create a permanent SAS data set, see Chapter 2, “Introduction to DATA Step Processing,” on page 19.
Programming Language
Elements of the SAS Language
The statements that created the data set WEIGHT_CLUB are part of the SAS programming language. The SAS language contains statements, expressions, functions and CALL routines, options, formats, and informats – elements that many programming languages share. However, the way you use the elements of the SAS language depends on certain programming rules. The most important rules are listed in the next two sections.
What Is the SAS System? Data Analysis and Reporting Utilities 7
Output 1.1 Displaying the Values in a SAS Data Set
Health Club Data 1 Id Start End Obs Number Name Team Weight Weight Loss 1 1023 David Shaw red 189 165 24 2 1049 Amelia Serrano yellow 145 124 21 3 1219 Alan Nance red 210 192 18 4 1246 Ravi Sinha yellow 194 177 17 5 1078 Ashley McKnight red 127 118 9
To produce a table showing mean starting weight, ending weight, and weight loss for each team, use the TABULATE procedure.
options linesize=80 pagesize=60 pageno=1 nodate;
proc tabulate data=weight_club; class team; var StartWeight EndWeight Loss; table team, mean*(StartWeight EndWeight Loss); title ’Mean Starting Weight, Ending Weight,’; title2 ’and Weight Loss’; run; The following output shows the results:
Output 1.2 Table of Mean Values for Each Team
Mean Starting Weight, Ending Weight, 1 and Weight Loss
| | Mean | | |--------------------------------------| | |StartWeight | EndWeight | Loss | |------------------+------------+------------+------------| |Team | | | | |------------------| | | | |red | 175.33| 158.33| 17.00| |------------------+------------+------------+------------| |yellow | 169.50| 150.50| 19.00|
A portion of a SAS program that begins with a PROC (procedure) statement and ends with a RUN statement (or is ended by another PROC or DATA statement) is called a PROC step. Both of the PROC steps that create the previous two outputs comprise the following elements: