Introduction t SAS Programming
统计代写 | report代做 | sas编程 – 这是一个关于sas的题目, 主要考察了关于sas编程的内容,是一个比较经典的题目, 是有一定代表意义的统计/sas/report等代写方向
Introduction t SASo
Programming
Lily Xu, Ohlone College, Fremont, CA
ABSTRACT Data is everywhere today and SAS skills are in high demand. This workshop is designed for those who have little or no previous programming experience in SAS. From the workshop, you will learn how to:
- write simple SAS programs
- read raw data files and existing data sets
- create temporary and permanent SAS data sets
- generate simple statistical reports
You will also have the opport unity to gain some hands-on programming experience on basic SAS procedures.
INTRODUCTION SAS is a powerful data management and statistical analysis software package. It is used extensively in clinical and academic research, government, finance, and biotech industry. SAS is available on most currently available operating systems. In this workshop, we will learn how to write simple SAS programs, conduct elementary statistical analysis, and present the output results within the SAS window environment.
FUNCTIONALITY OF SAS SOFTWARE The basic functionality of SAS is built around the following four data-driven tasks:
- Data Access
- Data Management
- Data Analysis
- Data Presentation
BASIC FILE TYPES USED IN SAS
- Raw Data Files are nonsoftware-specific files that contain records and fields
- SAS Data Sets are files specific to SAS that contain variables and observations, it can be created only by SAS and can be read only by SAS
- SAS Program Files contain SAS program code
COMPONENTS OF A SAS PROGRAM
A SAS program is a sequence of steps that the user submits for execution. There are only two kinds of steps: DATA
and PROC. Typically, DATA steps read both raw data files and SAS data sets create new SAS data sets. PROC
steps are typically used to process SAS data sets by invoking a prewritten program called a SAS procedure to create
reports (Figure 1).
Raw
Data
Raw
Data
DATA
Step
DATA
Step
ReportReport
SAS
Data
Set
SAS
Data
Set
PROC
Step
PROC
Step
Fi gure 1
COMPONENTS OF A STEP A teps is a sequence of one or more statements. A statement usually starts with a keyword and always ends in a semicolon ( ; ) SAS is very sensitive to semicolons.
THE SAS WINDOWING ENVIRONMENT SAS software provides the SAS windowing environment , an interactive environment that enables the entry and execution of SAS program code (Figure 2).
Figure 2
The Program Editor window enables SAS program code to be entered from the keyboard and submitted for execution. The Log window displays the SAS program code submitted for execution and messages from SAS indicating the status of the program execution. The Output window displays reports generated by the SAS program.
READING A RAW DATA FILE IN A DATA STEP The DATA statement names the SAS data set being created and signals the beginning of the DATA step. The INFILE statement names the raw data file to be read. The INPUT statement describes the fields in each raw data record to SAS. The statements Data, INFILE, and INPUT must be specified in the order in which they appear above. A SAS data set contains two parts, data and descriptor.
DATA health_infile; INFILE "C:\SAS workshop WUSS 2011\health.txt"; INPUT name $ age gender $ height weight ex; RUN ;
A raw data file can also be read directly from a SAS file (Figure 3).
DATA health_datalines; INPUT name $ age gender $ height weight ex; DATALINES; Jim 54 M 56 130 2 Lily 26 F 54 110 1 . . . RUN;
Figure 3
PROC PRINT This procedure displays the data portion of a SAS data set (Figure 4).
PROC PRINT DATA = health_datalines; TITLE "health_datalines"; RUN ;
Figure 4
PROC CONTENTS This procedure displays the descriptor portion of a SAS data set (Figure 5)
PROC CONTENTS DATA=health_datalines; RUN ;
Figure 5
CREATING A PERMANENT DATA SET Permanent data sets are created in order to have a SAS data set that exists after ending the SAS session. All SAS data sets have a two-level name. A SAS data library is a collection of SAS files that are recognized as a unit by the SAS system. The SAS data sets stored in the temporary SAS data library WORK are deleted at the end of each SAS session.
The LIBNAME statement can be used to create a permanent SAS data library. It is not part of a DATA step or a PROC step. By default, the libref remains assigned until the end of the SAS session.
Windows Example (Figure 6).
LIBNAME lily "C:\WUSS2011";
DATA lily.health_infile; INFILE "C:\WUSS2011\health.txt"; INPUT name $ age gender $ height weight ex; RUN ;
Figure 6
Reading an existing SAS data set (Figure 7).
Figure 7
CREATING STATISTICAL REPORTS A statistical report is created to display statistical information not available in a list report.
PROC MEANS A SAS summary report produces simple descriptive statistics for numeric variables. Example of a SAS Summary Report (Figure 8):
Figure 8
By default, the PROC MEANS step displays descriptive statistics for all the numeric variables in the SAS data set.
The VAR statement permits the specification of only those variables that are desired. The CLASS statement permits
the specification of the variable(s) by which to group the data set.
PROC FREQ A SAS frequency report produces simple statistics that count how often individual values occur within a SAS data set. It calculates statistics including frequency, percent, cumulative frequency, and cumulative percent.
A one-way frequency table is generated by a single variable name on the TABLES statement (Figure 9).
Figure 9
By default, PROC FREQ displays frequency statistics for all variables in the SAS data set, both character and
numeric. The TABLES statement permits the specification of only those variables that are desired.
PROC SORT This procedure sorts observations enables you to create a list report with the observations in a particular order (Figure 10) .
Figure 10
If specifying to sort by two or more variables, the data set is arranged in the order of the first designated variable and then by the second designated variable if several observations have the same value for the first variable.
By default, the procedure sorts in ascending order and does not generate printed output. If a name for a new SAS data set is omitted, the original data set is replaced with the sorted observations.
ENHANCING A REPORT
To enhance a list report, the following statements can be added to the PROC PRINT step (Figure 11):
- TITLE statement(s)
- FOOTNOTE statement(s)
- LABEL statement
- FORMAT statement.
The order of these statements in a PROC PRINT step does not matter. If a LABEL statement is included, the LABEL option must be present on the PROC PRINT statement. A single FORMAT statement can associate the same format with several variables or different formats with different variables.
Figure 11
THE GCHART PROCEDURE You can use bar or pie charts to graphically summarize data (Figure 12 & 13). The chart variable determines the number of bars or slices produced within a graph and can be character or numeric. SUMVAR identifies the analysis variable.
PROC CHART G DATA=lily.scientist; VBAR JobTitle / SUMVAR=Salary TYPE=mean; TITLE ‘Bar Chart of Job Titles’; RUN ; PIE JobTitle / SUMVAR=Salary TYPE=sum FILL=x EXPLODE=’Scientist1′; FORMAT Salary DOLLAR8.; TITLE ‘Pie Chart of Job Titles’; RUN; QUIT ;
- Figure 12 &
THE SAS HELP FACILITY
Note – The Help facility can also be accessed from a web browser at the following link: http://support.sas.com/documentation/index.html
CONCLUSION In this workshop, we have introduced the SAS window environment, gained some hands-on SAS programming experience, and learned basics SAS skills. In todays data world, knowing the power of SAS software and mastering SAS programming skills means more job opportunities and security.
REFERENCES SAS Institute (1999) SAS Companion for the Microsoft Windows Environment, Version 8, Cary, NC: SAS Institute Inc.
TRADEMARK 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 trademarks of their respective companies.
AUTHOR CONTACT Lily Xu Ohlone College 43600 Mission Boulevard Fremont, CA 94539- [email protected]