SAS Programming Introduction to SAS.

Slides:



Advertisements
Similar presentations
How to Import an Excel File Using the SAS Import Wizard SAS 9 for Windows.
Advertisements

The INFILE Statement Reading files into SAS from an outside source: A Very Useful Tool!
Statistical Methods Lynne Stokes Department of Statistical Science Lecture 7: Introduction to SAS Programming Language.
EndNote. What is EndNote:  EndNote is referencing software that enables you to create a database of references from your readings. Your database of references.
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.
Today: Run SAS programs on Saturn (UNIX tutorial) Runs SAS programs on the PC.
Ann Arbor ASA ‘Up and Running’ Series: SPSS Prepared by volunteers of the Ann Arbor Chapter of the American Statistical Association, in cooperation with.
Introduction to SAS ISYS 650. What Is SAS? SAS is a collection of modules that are used to process and analyze data. It began in the late ’60s and early.
Pet Fish and High Cholesterol in the WHI OS: An Analysis Example Joe Larson 5 / 6 / 09.
Sensitivity Analysis A systematic way of asking “what-if” scenario questions in order to understand what outcomes could possibly occur that would affect.
RIMS II Online Order and Delivery System Tutorial on Downloading and Viewing Multipliers.
Introduction to SPSS (For SPSS Version 16.0)
Understanding SAS Data Step Processing Alan C. Elliott stattutorials.com.
Creating SAS® Data Sets
SAS Workshop Lecture 1 Lecturer: Annie N. Simpson, MSc.
Introduction to SAS BIO 226 – Spring Outline Windows and common rules Getting the data –The PRINT and CONTENT Procedures Manipulating the data.
Introduction to SAS. What is SAS? SAS originally stood for “Statistical Analysis System”. SAS is a computer software system that provides all the tools.
EPIB 698C Lecture 2 Notes Instructor: Raul Cruz 2/14/11 1.
Chapter 1: Introduction to SAS  SAS programs: A sequence of statements in a particular order  Rules for SAS statements: –Every SAS statement ends in.
Lesson 2 Topic - Reading in data Chapter 2 (Little SAS Book)
Introduction to SAS Essentials Mastering SAS for Data Analytics
ISU Basic SAS commands Laboratory No. 1 Computer Techniques for Biological Research Animal Science 500 Ken Stalder, Professor Department of Animal Science.
Using Microsoft Visual Studio 2005 Original by Suma Rao Revised by John G. McMahon ( 9/6/2008 )
SAS: The last of the great mainframe stats packages STA431 Winter/Spring 2013.
1 EPIB 698E Lecture 1 Notes Instructor: Raul Cruz 7/9/13.
1 Data Manipulation (with SQL) HRP223 – 2010 October 13, 2010 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This.
Lesson 6 - Topics Reading SAS datasets Subsetting SAS datasets Merging SAS datasets.
EndNote. What is EndNote? EndNote is referencing software that enables you to create a database of references from your readings.
11/25/2015Slide 1 Scripts are short programs that repeat sequences of SPSS commands. SPSS includes a computer language called Sax Basic for the creation.
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.
Analysis Introduction Data files, SPSS, and Survey Statistics.
Chapter 1: Overview of SAS System Basic Concepts of SAS System.
Trinity College Dublin, The University of Dublin GE3M25: Computer Programming for Biologists Python Karsten Hokamp, PhD Genetics TCD, 03/11/2015.
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.
1 Introduction to SAS Available at
Lesson 2 Topic - Reading in data Programs 1 and 2 in course notes –Chapter 2 (Little SAS Book)
1 Data Manipulation (with SQL) HRP223 – 2009 October 12, 2009 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This.
Real Time Remote Access Comparing SAS and SPSS David Price Quy Do April 2013.
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.
HRP Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected by copyright law and.
Based on Learning SAS by Example: A Programmer’s Guide Chapters 1 & 2
Finance Business Solutions – User Support & Training
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.
LINGO TUTORIAL.
SAS: The last of the great mainframe stats packages
Introduction to SPSS.
Instructor: Raul Cruz-Cano 7/9/2012
Chapter 2: Getting Data into SAS
DEPARTMENT OF COMPUTER SCIENCE
LINDSEY BREWER CSSCR (CENTER FOR SOCIAL SCIENCE COMPUTATION AND RESEARCH) UNIVERSITY OF WASHINGTON September 17, 2009 Introduction to SPSS (Version 16)
How to Import an Excel File
SAS Output Delivery System
Chapter 1: Introduction to SAS
Instructor: Raul Cruz-Cano
Tamara Arenovich Tony Panzarella
EndNote by: fatimah alotaibi.
SAS Essentials How SAS Thinks
Introduction to SAS A SAS program is a list of SAS statements executed in order Every SAS statement ends with a semicolon! SAS statements can be in caps.
SAS Libname Quiz (You have 5 mins to complete, fill in the blanks)
SAS Programming Training
Stata Basic Course Lab 2.
Data Manipulation (with SQL)
Running a Java Program using Blue Jay.
Instructor: Raul Cruz 9/4/13
Introduction to SAS Essentials Mastering SAS for Data Analytics
Presentation transcript:

SAS Programming Introduction to SAS

Instructor Sam Lam Programming Consultant / Instructor Website: www.SASCrunch.com Email: klam@sascrunch.com

Today’s Topic Concepts: SAS Overview SAS Windows Data set and Library Data Step Programming: Creating a SAS data set INPUT and DATALINES SET statement Creating a Permanent Library Saving a SAS data set Functions Sum Mean, Min, Max Substr Index, Indexc And more …

SAS Overview

What is SAS? SAS stands for Statistical Analysis System (Software) Started in 1966 in University of North Carolina Currently used in more than 15 industries such as life science, marketing, finance, government, hotel, manufacturing ...etc.

What does SAS do? SAS is used to turn raw data into information where business decision can be made!

What does SAS do? Example 1: Data Mining Businesses make better marketing decision by extracting extra consumer insights from data using SAS

What does SAS do? Example 2: Life Science Pharmaceutical companies analyze the effectiveness of the newly developed clinical treatment using SAS

What does SAS do? Example 3: Fraud Detection Financial institutes develop the fraud detection system using SAS

Major Competitions R SPSS

SAS Components There are many individual components in SAS: SAS Base SAS/STAT SAS/GRAPH Mining Enterprise

SAS Basics

3 SAS Windows Editor Window Log Window Output Window

Editor Window The window where coding takes place Click the “running man” icon to compile the program Highlight the code to run only the highlighted part of the program F3 = short cut in running the code

Log Window The window showing the programming status (errors) when compiled Error message (in red) and Warning message (in green) should be cleaned up

Output Window The window where statistical results are displayed.

SAS Data set

SAS Data set Data set is the file where data is being stored Contains variable (column) and observation (row) Temporary vs. Permanent data set

SAS Data set Characteristics: Data cannot be modified without coding (unlike Excel spreadsheet) Proc Contents shows the descriptor portion of the data set

Data Portion vs. Descriptor Portion Data portion shows the actual contents of the data set such as variables and observations Descriptor portion shows the details of the data set such as the data set size, # of observations and list of variables.

Proc Contents Example Proc Contents Data=Test; Run;

SAS Variable

SAS Variable There are 6 attributes that define each variables: Name, Label, Length, Type, Format and Informat

Data Step

What is Data Step? Data Step is the basic programming unit of SAS. It is used to create data sets in SAS.

Basic Data Step Characteristics It starts with Data and ends with Run. Every complete line of code ends with a semi-colon. Data Step Structure: Data {name}; {coding}; Run;

Data Step Example Data Example; a = 1; Run;

Programming Tips 1. SAS is not sensitive to case 2. SAS is not sensitive to indentation

Creating a Data set

1. INPUT and DATALINES statements Example: Data Test; INPUT a b; DATALINES; 1 2 1 3 ; run;

1. INPUT and DATALINES statements Note: (1) The syntax INPUT is used to specify the variables to be created. In our example, variable a and variable b are created. (2) The syntax DATALINES specifies where the data should be read in.

Exercise 1 Create a new called Report. This data set should have 3 variables: Student, Gender and Results. The 3 variables should contain the following data: John M 90 Mary F 97 Peter M 77

2. SET Statement Example Data Report2; SET Report; Run;

2. SET Statement Example 2 Data Report2; SET Report; IF Gender = “M”; Run;

2. SET Statement Example 3 Data Report2; SET Report; IF Result >=90; Run;

3. SET Statement Example 4 Data Report2; SET Report; KEEP Student Results; Run;

SAS Library

Library is the folder containing the SAS data sets. SAS Library Library is the folder containing the SAS data sets. SAS dataset MUST be placed in a SAS library before being used in SAS.

SAS Library There are two types of library: Work Library vs. Permanent Library

Work Library Work library contains working datasets Datasets from the Work library will be deleted once the system is terminated

Accessing Permanent Library

Accessing Permanent Library In order to access the data sets from the permanent library, you need to use library reference. Example Data Cars; Set SASHelp.Cars; Run;

Library Reference Set SASHelp.Cars; The library reference allows you to refer to the data set from the correct library. SASHelp.Cars = The Cars data set from the SASHelp library Work.Cars = The Cars data set from the Work library.

Library Reference = Important note: The library reference is not needed when refering to a data set from the WORK library. Data Work.Car; Car = 10; Run; Data Cars; Car = 10; Run; =

Accessing Existing Data Sets

Creating a Permanent library Libname Statement: LIBNAME RyerSAS “c:\path";

Creating a Permanent library LIBNAME RyerSAS “c:\path”; LIBNAME: The syntax creating the library in SAS RyerSAS: The name of the library created “c:\path": The path to the Windows directory.

Creating a Permanent library Step 2: Check the Log window to see if there is any error or warning message.

Creating a Permanent library If everything is fine, there should be a new library created!

Exercise Download the zip file from the link below: http://www.sascrunch.com/ryerson.html Save the data sets into the Windows directory.

Exercise 2 Copy the ForestFire data set into the WORK library.

Programming Tips It is a good programming practice to copy the data set into the WORK library before modifying the data. The permanent library saves the “source” data. You do not want to modify it.

Saving the dataset into a Windows directory

Saving a dataset LIBNAME RyerSAS “c:\path"; Data RyerSAS.FIRE2; Set FirestFore; Run;

Note: (1) In order to put the data set into the RyerSAS library (instead of the Work library), we have to add the library reference before the dataset name. RyerSAS is the library reference in our example.

Note: (2) The SET function copies the content from the ForestFire dataset into the RyerSAS.FIRE2 dataset.