Into to SAS ®. 2 List the components of a SAS program. Open an existing SAS program and run it. Objectives.

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.
Chapter 17 Read Raw Data in Fixed Format using Formatted Input Objectives Distinguish between standard and nonstandard numeric data Read standard fixed-field.
Introduction to SAS Programming Christina L. Ughrin Statistical Software Consulting Some notes pulled from SAS Programming I: Essentials Training.
The Information Delivery Process Data In Information Out ManageOrganizeExploit.
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.
SAS ® Regression Essentials. 2 List the components of a SAS program. Open an existing SAS program and run it. Objectives.
NonParametric Statistics using SAS. 2 List the components of a SAS program. Open an existing SAS program and run it. Objectives.
Guide To UNIX Using Linux Third Edition
1 Computer Applications in Epidemiology Dongmei Li Lecture 26 5/6/2009.
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.
Creating SAS® Data Sets
How to start using SAS.
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.
FORMAT FESTIVAL AN INTRODUCTION TO SAS® FORMATS AND INFORMATS By David Maddox.
Chapter Seven Advanced Shell Programming. 2 Lesson A Developing a Fully Featured Program.
XP Tutorial 6New Perspectives on HTML and XHTML, Comprehensive 1 Creating Web Page Forms Designing a Product Registration Form Tutorial 6.
11 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Importing Text Files 2.4 Editing Tables in the.
Chapter 2: Working with Data in a Project
Introduction to Access By Mary Ann Chaney and Alicia Harkleroad.
Lecture 5 Sorting, Printing, and Summarizing Your Data.
Chapter 21 Reading Hierarchical Files Reading Hierarchical Raw Data Files.
1 Experimental Statistics - week 4 Chapter 8: 1-factor ANOVA models Using SAS.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Chapter 20 Creating Multiple Observations from a Single Record Objectives Create multiple observations from a single record containing repeating blocks.
Introduction to SAS. What is SAS? SAS originally stood for “Statistical Analysis System”. SAS is a computer software system that provides all the tools.
©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina Chapter 17 supplement: Review of Formatting Data STAT 541.
SAS 介绍和举例 Presented by 经济实验教学中心 商务数据挖掘中心. Raw Data Read in Data Process Data (Create new variables) Output Data (Create SAS Dataset) Analyze Data Using.
Input, Output, and Processing
EPIB 698C Lecture 2 Notes Instructor: Raul Cruz 2/14/11 1.
BMTRY 789 Lecture 2 SAS Syntax, entering raw data, etc. Lecturer: Annie N. Simpson, MSc. Readings – Chapters 1, 2, 12, & 13 Lab Problems 1.1, 1.2, 1.3,
I OWA S TATE U NIVERSITY Department of Animal Science Getting Your Data Into SAS (Chapter 2 in the Little SAS Book) Animal Science 500 Lecture No. 3 September.
Lesson 2 Topic - Reading in data Chapter 2 (Little SAS Book)
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting MySQL – Inserting Data.
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.
Conversion Functions.
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.
ISQS 6347, Data & Text Mining 1 ISQS 6339, Data Management & Business Intelligence Data Preparation for Analytics Using SAS Zhangxi Lin Texas Tech University.
1 Statistical Software Programming. STAT 6360 –Statistical Software Programming Data Input in SAS Many ways to get your data into SAS: –Through data entry.
Chapter 1: Overview of SAS System Basic Concepts of SAS System.
How to start using SAS SARBAJIT MUKHERJEE. WHAT IS SAS? SAS stands for Statistical Analysis System. Useful for the following types of task: 1. Data entry,
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
SAS for Data Management and Analysis
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.
Chapter 18 Reading Free-Format Data. 2 Objectives Read free-format data not recognized in fixed fields. Read free-format data separated by non-blank delimiters,
ISQS 6347, Data & Text Mining 1 ISQS 6339, Data Management & Business Intelligence Data Preparation for Analytics Using SAS Zhangxi Lin Texas Tech University.
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.
Based on Learning SAS by Example: A Programmer’s Guide Chapters 1 & 2
Online Programming| Online Training| Real Time Projects | Certifications |Online Classes| Corporate Training |Jobs| CONTACT US: STANSYS SOFTWARE SOLUTIONS.
Copyright 2009 The Little Engine That Could: Using EXCEL LIBNAME Engine Options to Enhance Data Transfers between SAS® and Microsoft® Excel Files William.
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.
Lesson 2 Topic - Reading raw data into SAS
Introduction to SAS®.
Instructor: Raul Cruz-Cano 7/9/2012
Chapter 2: Getting Data into SAS
ORACLE SQL Developer & SQLPLUS Statements
Chapter 3 The DATA DIVISION.
SAS® Regression Essentials
Introduction to SAS Essentials Mastering SAS for Data Analytics
Introduction to SAS Essentials Mastering SAS for Data Analytics
Presentation transcript:

Into to SAS ®

2 List the components of a SAS program. Open an existing SAS program and run it. Objectives

3 DATA steps are typically used to create SAS data sets. PROC steps are typically used to process SAS data sets (that is, generate reports and graphs, edit data, and sort data). A SAS program is a sequence of steps that the user submits for execution. Raw Data DATA Step Report SAS Data Set PROC Step SAS Programs

4 data work.staff; infile 'raw-data-file'; input LastName $ 1-20 FirstName $ JobTitle $ Salary 54-59; run; proc print data=work.staff; proc means data=work.staff; class JobTitle; var Salary; run; Step Boundaries

5 Interactive windows enable you to interface with SAS. SAS Windowing Environment

6 Open the SAS program “example.sas.” Submit the program and examine the results. Data for today's class located at Exercises

7 Learn the two fundamental SAS syntax programming rules. Learn to create a SAS dataset from a text file. Write a Data Step to read a course data file. Objectives

8 SAS statements have these characteristics: usually begin with an identifying keyword always end with a semicolon data staff; input LastName $ FirstName $ JobTitle $ Salary; datalines; …insert text here… run; proc print data=staff; run; Fundamental SAS Syntax Rules

9 Reading Raw Data Files /11/00LAX /11/00DFW /12/00LAX /12/00dfw /13/00LAX /13/00DFW /14/00LaX /14/00DFW /15/00LAX /15/00DFW Data for flights from New York to Dallas (DFW) and Los Angeles (LAX) is stored in a raw data file. Create a SAS data set from the raw data.

10 data SAS-data-set-name; infile 'raw-data-filename'; input input-specifications; Creating a SAS Data Set /11/00LAX /11/00DFW /12/00LAX Raw Data File DATA Step SAS Data Set In order to create a SAS data set from a raw data file, you must do the following: 1.Start a DATA step and name the SAS data set being created (DATA statement). 2.Identify the location of the raw data file to read (INFILE statement). 3.Describe how to read the data fields from the raw data file (INPUT statement). run;

11 Creating a SAS Data Set General form of the DATA statement: Example:This DATA statement creates a temporary SAS data set named dfwlax : Example:This DATA statement creates a permanent SAS data set named dfwlax : DATA libref.SAS-data-set(s); data work.dfwlax; libname ia 'SAS-data-library'; data ia.dfwlax;

12 Pointing to a Raw Data File General form of the INFILE statement: Examples: The PAD option in the INFILE statement is useful for reading variable-length records typically found in Windows and UNIX environments. z/OS (OS/390) infile 'userid.prog1.dfwlax'; UNIX infile '/users/userid/dfwlax.dat'; Windows infile 'c:\workshop\winsas\prog1\dfwlax.dat'; INFILE 'filename' ;

13 Reading Data Fields General form of the INPUT statement: input-specifications names the SAS variables identifies the variables as character or numeric specifies the locations of the fields in the raw data can be specified as column, formatted, list, or named input. INPUT input-specifications;

14 Reading Data Using Column Input Column input is appropriate for reading the following: data in fixed columns standard character and numeric data General form of a column INPUT statement: Examples of standard numeric data: The term standard data refers to character and numeric data that SAS recognizes automatically E E-3 INPUT variable startcol-endcol... ;

15 Reading Data Using Column Input 43912/11/00LAX /11/00DFW /12/00LAX input Flight $ 1-3 Date $ 4-11 Dest $ FirstClass Economy 18-20;...

16 Creating Temporary SAS Data Sets NOTE: The data set WORK.DFWLAX has 10 observations and 5 variables. data work.dfwlax; infile 'raw-data-file'; input Flight $ 1-3 Date $ 4-11 Dest $ FirstClass Economy 18-20; run; Store the dfwlax data set in the work library. c06s1d1

17 Assignment Statements: Creating variables NOTE: The data set WORK.DFWLAX has 10 observations and 5 variables. data work.dfwlax; infile 'raw-data-file'; input Flight $ 1-3 Date $ 4-11 Dest $ FirstClass Economy 18-20; Total=Firstclass+Economy; LogEconomy=LOG(Economy); run; c06s1d1

18 Formatted input is appropriate for reading the following: data in fixed columns standard and nonstandard character and numeric data calendar values to be converted to SAS date values Reading Data Using Formatted Input

19 Date values that are stored as SAS dates are special numeric values. A SAS date value is interpreted as the number of days between January 1, 1960, and a specific date. 01JAN JAN JAN /01/195901/01/ /01/1961 informat format Working with Date Values

20 General form of the INPUT statement with formatted input: Reading Data Using Formatted Input INPUT pointer-control variable informat... ; Formatted input is used to read data values by doing the following: moving the input pointer to the starting position of the field specifying a variable name specifying an informat

21 Pointer the pointer to column n. +nmoves the pointer n positions. An informat specifies the following: the width of the input field how to read the data values that are stored in the field Reading Data Using Formatted Input

22 informat-namew. An informat is an instruction that SAS uses to read data values. SAS informats have the following form: Informat name Number of decimal places Indicates a character informat What Is a SAS Informat? Total width of the field to read Required delimiter

23 w. standard numeric informat Raw Data Value Informat SAS Data Value 8.0 Selected Informats 8.0

24 COMMAw. reads numeric data and removes selected nonnumeric characters such as dollar signs and commas. Raw Data Value Informat SAS Data Value MMDDYYw. reads dates of the form mm/dd/yyyy. Raw Data Value Informat SAS Data Value COMMA7.0 MMDDYY8. Selected Informats

25 $8. Selected Informats $w. standard character informat (removes leading blanks) Raw Data Value Informat SAS Data Value

26 SAS uses date informats to read and convert dates to SAS date values. 10/29/2001 MMDDYY /29/01 MMDDYY OCT2001 DATE /10/2001 DDMMYY Informat Raw Data Value Converted Value Examples: Number of days between 01JAN1960 and 29OCT2001 Converting Dates to SAS Date Values

/11/00LAX /11/00DFW /12/00LAX Reading Data: Formatted Input Flight Date Dest FirstClass Economy 3.;...

28 Raw Data File 43912/11/00LAX /11/00DFW /12/00LAX Reading Data: Formatted Input data work.dfwlax; infile 'raw-data-file'; Flight Date Dest FirstClass Economy 3.; run; c06s2d1

29 The SAS System First Obs Flight Date Dest Class Economy LAX DFW LAX dfw LAX DFW LaX DFW LAX DFW Reading Data: Formatted Input proc print data=work.dfwlax; run; SAS date values c06s2d1

30 List Input with the Default Delimiter The data is not in fixed columns. The fields are separated by spaces. There is one nonstandard field. 51 4feb nov oct feb jun dec

31 Delimiters tab characters A space (blank) is the default delimiter. blankscommas Common delimiters are

32 List Input General form of the INPUT statement for list input: You must specify the variables in the order that they appear in the raw data file. Specify a $ after the variable name if it is character. No symbol after the variable name indicates a numeric variable. INPUT var-1 $ var-2... var-n;

33 Input Data The second field is a date. How does SAS store date values? feb nov oct feb jun dec

34 Informats To read nonstandard data, you must apply an informat. General form of an informat: Informats are instructions that specify how SAS reads raw data. INFORMAT-NAME.

35 Specifying an Informat To specify an informat when using list input, use the colon (:) format modifier in the INPUT statement between the variable name and the informat. General form of a format modifier in an INPUT statement: INPUT variable : informat;

36 Reading a Delimited Raw Data File data airplanes; infile 'raw-data-file'; input ID $ InService : date9. PassCap CargoCap; run;

37 Non-Default Delimiter The fields are separated by commas , 4feb1989,132, , 11nov1989,152, , 22oct1991,90, , 4feb1993,172, , 24jun1993, 170, , 20dec1994, 180, 520

38 Using the DLM= Option The DLM= option sets a character or characters that SAS recognizes as a delimiter in the raw data file. General form of the INFILE statement with the DLM= option: Any character you can type on your keyboard can be a delimiter. You can also use hexadecimal characters. INFILE 'raw-data-file' DLM='delimiter(s)';

39 Multiple Records Per Observation A raw data file has three records per employee. Record 1 contains the first and last names, record 2 contains the city and state of residence, and record 3 contains the employee’s phone number. Farr, Sue Anaheim, CA Anderson, Kay B. Chicago, IL Tennenbaum, Mary Ann Jefferson, MO

40 Desired Output The SAS data set should have one observation per employee. LName FName City State Phone Farr Sue Anaheim CA Anderson Kay B. Chicago IL Tennenbaum Mary Ann Jefferson MO

41 data address; infile 'raw-data-file' dlm=','; input #1 LName $ FName $ #2 City $ State $ #3 Phone $; run; Reading Multiple Records per Observation...