Computing with SAS Software A SAS program consists of SAS statements. 1. The DATA step consists of SAS statements that define your data and create a SAS.

Slides:



Advertisements
Similar presentations
The INFILE Statement Reading files into SAS from an outside source: A Very Useful Tool!
Advertisements

Statistical Methods Lynne Stokes Department of Statistical Science Lecture 7: Introduction to SAS Programming Language.
SAS Programming:File Merging and Manipulation. Reading External Files (review) data barf; * create the dataset BARF; infile ’s:\mysas\Table7.1'; * open.
Slide C.1 SAS MathematicalMarketing Appendix C: SAS Software Uses of SAS  CRM  datamining  data warehousing  linear programming  forecasting  econometrics.
Chapter 17 Read Raw Data in Fixed Format using Formatted Input Objectives Distinguish between standard and nonstandard numeric data Read standard fixed-field.
Chapter 3: Editing and Debugging SAS Programs. Some useful tips of using Program Editor Add line number: In the Command Box, type num, enter. Save SAS.
Introduction to SAS Programming Christina L. Ughrin Statistical Software Consulting Some notes pulled from SAS Programming I: Essentials Training.
Statistics in Science  Introducing SAS ® software Acknowlegements to David Williams Caroline Brophy.
SAS Programming: Working With Variables. Data Step Manipulations New variables should be created during a Data step Existing variables should be manipulated.
I OWA S TATE U NIVERSITY Department of Animal Science Getting Started Using SAS Software Animal Science 500 Lecture No. 2.
Today: Run SAS programs on Saturn (UNIX tutorial) Runs SAS programs on the PC.
Biostatistical Methods II PubH 6415 Spring PubH 6415 – Biostatistics I Instructor: Susan Telke (office hours: lecture.
Quick Data Summaries in SAS Start by bringing in data –Use permanent data set for these examples Proc Tabulate –Produces summaries very quickly and easily.
Categorical Data Analysis using SAS. 2 List the components of a SAS program. Open an existing SAS program and run it. Discuss the Chi Square Test of Independence.
NonParametric Statistics using SAS. 2 List the components of a SAS program. Open an existing SAS program and run it. Objectives.
1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR, etc. The most.
1 Computer Applications in Epidemiology Dongmei Li Lecture 26 5/6/2009.
SAS Workshop INTRODUCTORY ASPECTS SPRING 2012 January 20121K. F. O'Brien.
Understanding SAS Data Step Processing Alan C. Elliott stattutorials.com.
Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS Essentials - Elliott & Woodward1.
Into to SAS ®. 2 List the components of a SAS program. Open an existing SAS program and run it. Objectives.
Introduction to SAS Lecture 2 Brian Healy.
SAS ® ANOVA Essentials. 2 List the components of a SAS program. Open an existing SAS program and run it. Objectives.
Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities.
SAS Workshop Lecture 1 Lecturer: Annie N. Simpson, MSc.
Chapter 9 Producing Descriptive Statistics PROC MEANS; Summarize descriptive statistics for continuous numeric variables. PROC FREQ; Summarize frequency.
Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS ESSENTIALS -- Elliott & Woodward1.
Introduction to SAS BIO 226 – Spring Outline Windows and common rules Getting the data –The PRINT and CONTENT Procedures Manipulating the data.
1 Experimental Statistics - week 4 Chapter 8: 1-factor ANOVA models Using SAS.
Introduction to SAS. What is SAS? SAS originally stood for “Statistical Analysis System”. SAS is a computer software system that provides all the tools.
Exploring Engineering Chapter 3, Part 2 Introduction to Spreadsheets.
1 Experimental Statistics - week 2 Review: 2-sample t-tests paired t-tests Thursday: Meet in 15 Clements!! Bring Cody and Smith book.
Quantify the Example Data First, code and quantify the data (assign column locations & variable names) Use the sample data to create a data set from the.
Math 3400 Computer Applications of Statistics Lecture 1 Introduction and SAS Overview.
SAS 介绍和举例 Presented by 经济实验教学中心 商务数据挖掘中心. Raw Data Read in Data Process Data (Create new variables) Output Data (Create SAS Dataset) Analyze Data Using.
EPIB 698C Lecture 2 Notes Instructor: Raul Cruz 2/14/11 1.
Lesson 2 Topic - Reading in data Chapter 2 (Little SAS Book)
Introduction to SAS Essentials Mastering SAS for Data Analytics
A Simple Guide to Using SPSS ( Statistical Package for the Social Sciences) for Windows.
1 EPIB 698E Lecture 1 Notes Instructor: Raul Cruz 7/9/13.
Lesson 6 - Topics Reading SAS datasets Subsetting SAS datasets Merging SAS datasets.
How to start using SAS Tina Tian. The topics An overview of the SAS system Reading raw data/ create SAS data set Combining SAS data sets & Match merging.
Chapter 5 Reading and Manipulating SAS ® Data Sets and Creating Detailed Reports Xiaogang Su Department of Statistics University of Central Florida.
Chapter 4 concerns various SAS procedures (PROCs). Every PROC operates on: –the most recently created dataset –all the observations –all the appropriate.
Chapter 17: Formatting Data 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS Essentials - Elliott & Woodward1.
Chapter 1: Overview of SAS System Basic Concepts of SAS System.
An Introduction Katherine Nicholas & Liqiong Fan.
FORMAT statements can be used to change the look of your output –if FORMAT is in the DATA step, then the formats are permanent and stored with the dataset.
Using SPSS Next. An Introduction SPSS (the Statistical Package for the Social Sciences)
Chapter 2 Getting Data into SAS Directly enter data into SAS data sets –use the ViewTable window. You can define columns (variables) with the Column Attributes.
Chapter 17 Supplement: Alternatives to IF-THEN/ELSE Processing STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South.
1 PEER Session 02/04/15. 2  Multiple good data management software options exist – quantitative (e.g., SPSS), qualitative (e.g, atlas.ti), mixed (e.g.,
Lesson 2 Topic - Reading in data Programs 1 and 2 in course notes –Chapter 2 (Little SAS Book)
1 EPIB 698C Lecture 1 Instructor: Raul Cruz-Cano
SAS Programming Training Instructor:Greg Grandits TA: Textbooks:The Little SAS Book, 5th Edition Applied Statistics and the SAS Programming Language, 5.
The Urban Institute - SAS Training6/9/20161 SAS Training This SAS Training Course was designed to introduce users at The Urban Institute to SAS programming.
Data Entry, Coding & Cleaning SPSS Training Thomas Joshua, MS July, 2008.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 16 & 17 By Tasha Chapman, Oregon Health Authority.
Setting up your database And codebook. What is a codebook? It is a description of all your variables How they were created How they are scored Includes.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 5 & 6 By Ravi Mandal.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 3 & 4 By Tasha Chapman, Oregon Health Authority.
Instructor: Raul Cruz-Cano
Tamara Arenovich Tony Panzarella
Chapter 4: Sorting, Printing, Summarizing
Hans Baumgartner Penn State University
Introduction to SAS Essentials Mastering SAS for Data Analytics
Presentation transcript:

Computing with SAS Software A SAS program consists of SAS statements. 1. The DATA step consists of SAS statements that define your data and create a SAS data set. 2. The PROC steps are groups of SAS statements that indicate what kind of statistical analysis to perform The following slides present the DATA STEP commands to read the data into SAS.

The SAS Data Step RAW DATA DATA STEP SAS DATA SET Raw Data: Rows are observations and columns are variables This is created by entering data, reading raw data, or accessing files created by other software according to a specific syntax. AgeGenderExam gradeHomework grade 19F M F M M8385

In SAS nomenclature: – Columns specify Variables – Rows contain the Observations. The general form of the data step is DATA name; Statements; DATALINES ; NOTICE: All SAS statements end with a semicolon ";". Remember the most common cause of error in SAS is the omission of the semicolon. ALWAYS CHECK FOR IT!! Name is the SAS data set name

/* This is an example on how to input data into SAS */ TITLE 'Example of data input in SAS'; DATA grades; INPUT age gender $ exam hwork; DATALINES; 19 F M F M M ; Required: Semi-colon on a line by itself --- The null statement SAS data set name statement

Rules for SAS names Total number of characters: 8 or less (Prior to SAS version 8). Must start with a letter or an underscore ( _ ). Must not contain blanks Other rules For a missing value of an observation: – enter a period (.) for missing numeric – enter a blank ( ) for missing name (character variable).

The input statement It defines the variable name, type and location. 1. If data are in columns, use 2.To read several observations separated by at least one blank space: use the symbol at the end of the input line. Example: DATA grades; INPUT age gender $ exam hwork DATALINES; 19 F M F M M ; INPUT age 1-2 gender $ 4 exam 6-7 hwork 9-10; Col location

The datalines statement Immediately follows the input statement: DATA grades; INPUT age gender $ exam hwork DATALINES; 19 F M F M M ;

However, if the data are to be read from an external file (ex: mydata.txt), use the infile statement as follows: If data are in columns: DATA grades; INFILE ‘c:\tmp\grades.dat’; INPUT age 1-2 gender $ 4 exam 6-7 hwork 9-10; If data are NOT in columns: DATA grades; INFILE ‘c:\tmp\grades.dat’; INPUT age gender $ exam hwork

steps SAS Proc steps PROC DATA=dataset1 [options1]; [Statements / options2]; proc_name  name of the PROC being used, DATA=dataset1  name of the SAS data set to be analyzed (If omitted, the most recently created SAS data set is used.) Options and statements vary from PROC to PROC: Descriptions in your SAS manual and the Help Window!!

Is a procedure to display your data on screen (or into a file) as part of the output. PROC PRINT DATA=grades; TITLE2 'Listing of data'; TITLE3 'Exam and Homework grades'; RUN; PROC Print Example of data input in SAS Listing of data Exam and Homework grades Obs AGE GENDER EXAM HWORK 1 19 F M F M M 83 85

If we had more variables and we wanted to print only the variable age and gender, specify it in proc print by using the keyword var: proc print data = grades ; var age gender ; run;

Labeling variables Labeling variables: to describe the variables, you can attach labels to variable names. DATA Grades; INPUT AGE GENDER $ EXAM HWORK LABEL AGE=’Student’s age’ GENDER=’Student’s sex’ EXAM = ‘Final exam grade’ HWORK=’Homework grade’; DATALINES;...

 To format values of variables PROC FORMAT; VALUE $SX ‘M’=’Male’ ‘F’=’Female’; RUN; DATA GRADES; INPUT AGE GENDER $ EXAM HWORK; FORMAT GENDER $SX.; Notice the dot after $SX DATALINES;... PROC format REMEMBER: Labels: for names of variables Formats: for values of variables

Built-in formats in SAS Example of SAS Program for CSC323 Students' grades in Age order AGE GENDER EXAM HWORK 19 Female Male Male Female Male PROC SORT DATA=GRADES; BY AGE; RUN; PROC PRINT DATA=GRADES; TITLE2 "Students' grades in Age order"; ID AGE; VAR GENDER EXAM HWORK; RUN;

Data manipulation Data Transformations: Assignment statements create new variables. The usual arithmetic operations and transformations are available. DATA GRADES; INPUT AGE GENDER $ EXAM HWORK; MEANGRADE=(EXAM+HWORK)/2; AGE_LOG=LOG(AGE); DATALINES;...

/* Example of Program: Data on students’ grades*/ OPTIONS NODATE; /* Suppress the date that is normally printed in the output*/ TITLE 'Example of SAS Program for CSC323'; PROC FORMAT; VALUE $SX 'M'='Male' 'F'='Female';

/* It inputs the data; computes the final score as the average of the exam score and the homework grade and it assigns a letter grade */ DATA GRADES; INPUT AGE GENDER $ EXAM HWORK; FORMAT GENDER $SX.; FINAL= (EXAM + HWORK)/2; IF FINAL < 75 THEN GRADE ='C'; ELSE IF FINAL >=75 AND FINAL <=85 THEN GRADE = 'B'; ELSE IF FINAL >=85 THEN GRADE = 'A'; LABEL AGE='Student's age' GENDER='Student's sex' EXAM = 'Final exam grade' HWORK='Homework grade'; DATALINES; 19 F M F M M ;

/* It lists the student's grades in student's age order*/ PROC SORT DATA=GRADES; BY AGE; RUN; PROC PRINT DATA=GRADES; TITLE2 "Students' grades in Age order"; ID AGE; VAR GENDER EXAM HWORK FINAL GRADE; RUN;

Example of SAS Program for CSC323 Students' grades in Age order AGE GENDER EXAM HWORK FINAL GRADE 19 Female A 19 Male A 20 Male A 20 Female B 21 Male B Program Output