ECLT 5810 SAS Programming - Introduction

Similar documents
STAT 7000: Experimental Statistics I

Example1D.1.sas. * Procedures : ; * 1. print to show the dataset. ;

Epidemiology Principles of Biostatistics Chapter 3. Introduction to SAS. John Koval

Using an ICPSR set-up file to create a SAS dataset

ERROR: ERROR: ERROR:

Chapter 7 File Access. Chapter Table of Contents

Chapter 2: Getting Data Into SAS

Reading data in SAS and Descriptive Statistics

SAS PROGRAMMING AND APPLICATIONS (STAT 5110/6110): FALL 2015 Module 2

STAT:5400 Computing in Statistics

17. Reading free-format data. GIORGIO RUSSOLILLO - Cours de prépara)on à la cer)fica)on SAS «Base Programming» 386

DSCI 325: Handout 9 Sorting and Options for Printing Data in SAS Spring 2017

Quality Control of Clinical Data Listings with Proc Compare

Getting Your Data into SAS The Basics. Math 3210 Dr. Zeng Department of Mathematics California State University, Bakersfield

Level I: Getting comfortable with my data in SAS. Descriptive Statistics

Biostatistics 600 SAS Lab Supplement 1 Fall 2012

SAS Training Spring 2006

MARK CARPENTER, Ph.D.

Using a HASH Table to Reference Variables in an Array by Name. John Henry King, Hopper, Arkansas

Introductory Guide to SAS:

The INPUT Statement: Where

DSCI 325: Handout 2 Getting Data into SAS Spring 2017

Introduction to SAS. Cristina Murray-Krezan Research Assistant Professor of Internal Medicine Biostatistician, CTSC

Procedure for Stamping Source File Information on SAS Output Elizabeth Molloy & Breda O'Connor, ICON Clinical Research

Dr. Barbara Morgan Quantitative Methods

Lecture 1 Getting Started with SAS

Omitting Records with Invalid Default Values

Moving Data and Results Between SAS and Excel. Harry Droogendyk Stratia Consulting Inc.

ASSIGNMENT #2 ( *** ANSWERS ***) 1

Lab #1: Introduction to Basic SAS Operations

.txt - Exporting and Importing. Table of Contents

Introduction to SQL 4/24/2017. University of Iowa SAS Users Group. 1. Introduction and basic uses 2. Joins and Views 3. Reporting examples

SAS 101. Based on Learning SAS by Example: A Programmer s Guide Chapter 21, 22, & 23. By Tasha Chapman, Oregon Health Authority

Essentials of PDV: Directing the Aim to Understanding the DATA Step! Arthur Xuejun Li, City of Hope National Medical Center, Duarte, CA

You will be asked to enter your SUNet ID (Stanford University Network Identifier). See the following URL for information on obtaining a SUNet ID:

GET A GRIP ON MACROS IN JUST 50 MINUTES! Arthur Li, City of Hope Comprehensive Cancer Center, Duarte, CA

Formulas and Functions

SD10 A SAS MACRO FOR PERFORMING BACKWARD SELECTION IN PROC SURVEYREG

Lesson 1: Writing Your First JavaScript

Automating Descriptive Statistics

ST Lab 1 - The basics of SAS

You will learn: The structure of the Stata interface How to open files in Stata How to modify variable and value labels How to manipulate variables

An Introduction to Stata Part I: Data Management

Multiple Facts about Multilabel Formats

Base and Advance SAS

Introduction to DATA Step Programming SAS Basics II. Susan J. Slaughter, Avocet Solutions

Introduction to DATA Step Programming: SAS Basics II. Susan J. Slaughter, Avocet Solutions

EXST SAS Lab Lab #8: More data step and t-tests

An Introduction to Creating Multi- Sheet Microsoft Excel Workbooks the Easy Way with SAS

Maximizing Statistical Interactions Part II: Database Issues Provided by: The Biostatistics Collaboration Center (BCC) at Northwestern University

INTRODUCTION TO SAS HOW SAS WORKS READING RAW DATA INTO SAS

Final Stat 302, March 17, 2014

INTRODUCTION SAS Prepared by A. B. Billings West Virginia University May 1999 (updated August 2006)

Microsoft Word. Part 2. Hanging Indent

The easiest way to get these data into STATA is for you to fire up the STATA Data Editor and just type the data into the spreadsheet-like interface.

Stat 302 Statistical Software and Its Applications SAS: Data I/O

Introduction to SAS Mike Zdeb ( , #61

Arthur L. Carpenter California Occidental Consultants, Oceanside, California

A Step by Step Guide to Learning SAS

SAS seminar. The little SAS book Chapters 3 & 4. April 15, Åsa Klint. By LD Delwiche and SJ Slaughter. 3.1 Creating and Redefining variables

Compilation and Execution Simplifying Fractions. Loops If Statements. Variables Operations Using Functions Errors

Why & How To Use SAS Macro Language: Easy Ways To Get More Value & Power from Your SAS Software Tools

Sandra Hendren Health Data Institute

Mapping Clinical Data to a Standard Structure: A Table Driven Approach

STAT 3304/5304 Introduction to Statistical Computing. Introduction to SAS

(c) What is the result of running the following program? x = 3 f = function (y){y+x} g = function (y){x =10; f(y)} g (7) Solution: The result is 10.

MATH 707-ST: Introduction to Statistical Computing with SAS and R. MID-TERM EXAM (Writing part) Fall, (Time allowed: TWO Hours)

The INPUT Statement: Where It

Objective 1: Familiarize yourself with basic database terms and definitions. Objective 2: Familiarize yourself with the Access environment.

16. Reading raw data in fixed fields. GIORGIO RUSSOLILLO - Cours de prépara)on à la cer)fica)on SAS «Base Programming» 364

Basic Macro Processing Prepared by Destiny Corporation

proc print data=account; <insert statement here> run;

Web Mail Check v 1.0

Manju Muralidharan Priya. CS4PM Web Aesthetics and Development WEEK 11

Writing Programs in SAS Data I/O in SAS

EXCEL IMPORT user guide

A QUICK INTRODUCTION TO STATA

22S:166. Checking Values of Numeric Variables

Reporting from Base SAS Tips & Tricks. Fareeza Khurshed BC Cancer Agency

SAS Online Training: Course contents: Agenda:

Some _FILE_ Magic Mike Zdeb, FSL, University at Albany School of Public Health, Rensselaer, NY

PROC FORMAT. CMS SAS User Group Conference October 31, 2007 Dan Waldo

ssh tap sas913 sas

Unit 2 Fine-tuning Spreadsheets, Functions (AutoSum)

April 4, SAS General Introduction

Why & How To Use SAS Macro Language: Easy Ways To Get More Value & Power from Your SAS Software Tools

If You Need These OBS and These VARS, Then Drop IF, and Keep WHERE Jay Iyengar, Data Systems Consultants LLC

The Art of Defensive Programming: Coping with Unseen Data

An Introduction to Macros Deb Cassidy

Stat Wk 3. Stat 342 Notes. Week 3, Page 1 / 71

COMS 359: Interactive Media

USING SAS SOFTWARE TO COMPARE STRINGS OF VOLSERS IN A JCL JOB AND A TSO CLIST

Introduction to C++ General Rules, Conventions and Styles CS 16: Solving Problems with Computers I Lecture #2

Variables and Constants

NVIvo 11 workshop. Hui Bian Office for Faculty Excellence

Stata: A Brief Introduction Biostatistics

Ready To Become Really Productive Using PROC SQL? Sunil K. Gupta, Gupta Programming, Simi Valley, CA

Get Started Writing SAS Macros Luisa Hartman, Jane Liao, Merck Sharp & Dohme Corp.

MISSOVER, TRUNCOVER, and PAD, OH MY!! or Making Sense of the INFILE and INPUT Statements. Randall Cates, MPH, Technical Training Specialist

SSID User Guide and Policy

Transcription:

ECLT 5810 SAS Programming - Introduction

Why SAS? Able to process data set(s). Easy to handle multiple variables. Generate useful basic analysis Summary statistics Graphs Many companies and government agencies adopt it 2

SAS Programs SAS program goes here 3

SAS Programs Composed of SAS Statements All SAS Statements end with a Semi-colon EXCEPT Data lines Example SAS Statement: input name $ sex $ age height; Comment lines are preceded by * 4

SAS Variables Names <= 32 characters for SAS 9.0 or above <= 8 characters for SAS 8 or below Must begin with a letter 5

Composition of SAS Programs Beginning: Create a SAS data set Middle: Work with data using SAS procedures (PROCs) End: RUN the program 6

SAS Data and Data Sets SAS is flexible. Can read data from many sources Sometimes you can get SAS data sets from data sources (BLS, etc.) First step is to convert raw data to a SAS data set 7

A SAS Program: Beginning data testdata1; input id height weight gender $ age; datalines; 1 68 144 M 23 2 78 150 F 34 3 65 150 M 35 SAS Statements: data, input, datalines 8

Beginning: Data Step Processing data testdata1; input id height weight gender $ age; datalines; 1 68 144 M 23 2 78 150 F 34 3 65 150 M 35 data: Tells SAS the name of the SAS data set being created. 9

Beginning data testdata1; input id height weight gender $ age; datalines; 1 68 144 M 23 2 78 150 F 34 3 65 150 M 35 input: Tells SAS the names of the variables being read. varname $ means character data. 10

Beginning data testdata1; input id height weight gender $ age; datalines; 1 68 144 M 23 2 78 150 F 34 3 65 150 M 35 datalines/cards: Tells SAS the following lines are data. Data must follow 11

Delimiters Must separate variables on cards or external files Accomplished with delimiters Spaces are common, SAS default Can also use other characters, but must tell SAS 12

Some Definitions Field: Smallest unit of data. One observation of a variable. Can be either character (letters and numbers) or numeric (numbers only). Record: A single line of input. Contains one or more fields File: A collection of records 13

A Character Field input name $ sex $ age height weight; alfred M 14 69 112 alice F 13 56 84 barbara F 14 62 102 henry M 15 67 135 john M 16 70 165 sally F 16 63 120 ; 14

A Numeric Field input name $ sex $ age height weight; alfred M 14 69 112 alice F 13 56 84 barbara F 14 62 102 henry M 15 67 135 john M 16 70 165 sally F 16 63 120 ; 15

A Record input name $ sex $ age height weight; alfred M 14 69 112 alice F 13 56 84 barbara F 14 62 102 henry M 15 67 135 john M 16 70 165 sally F 16 63 120 ; 16

A File input name $ sex $ age height weight; alfred M 14 69 112 alice F 13 56 84 barbara F 14 62 102 henry M 15 67 135 john M 16 70 165 sally F 16 63 120 ; 17

Input Styles: List Input input x1 x2 m; * input the variables; This statement reads in the data in a SAS program. When only the variables are listed, with $ to indicate character variables, it s called List Input, the simplest input style in SAS. 18

Rules for List Input Fields must be separated by at least 1 blank Each field must appear in order Missing values must be represented by a placeholder ( a period. in this case) No embedded blanks in character fields Data must be in a standard format (e.g. text file) 19

Looking at Data in SAS After creating a SAS data set, it s a good idea to look at the data to make sure it was read correctly. You can use proc print to write the data to the output window, or you browse the data interactively. 20

Middle: Work with data proc print data=testdata1; title "A Data Set"; run; proc A SAS procedure. These are how you work with the data in SAS. There are many SAS procedures. print SAS procedure to create an output file. By default, uses the data from the last data statement. 21

Run Programs 22

Sample Output 23

Data Selection Use if command to select data data testdata1; input id height weight gender $ age; if gender= M ; datalines; 1 68 144 M 23 2 78 150 F 34 3 65 150 M 35 24

Sample Output 25

Summary Statistics in SAS Means and Standard Deviations can be easily calculated for variables in a SAS data set using the means procedure Format: proc means; var v1 v2 v3; List all the variables you want summary statistics for on the second line 26

Summary Statistics in SAS proc means; var height weight; run; 27

Output from proc means 28

A Sample Program data htwt; input name $ sex $ age height weight; x = height + weight; y = age**2; z = 3*age - 5; cards; alfred M 14 69 112 alice F 13 56 84 barbara F 14 62 102 henry M 15 67 135 john M 16 70 165 sally F 16 63 120 ; proc means; var x y z; title 'Summary Statistics'; proc print; title 'Height-Weight Example #1'; run; 29

The Output 30

Errors in SAS Programs You will make them Common ones: Leaving off a semi-colon from the end of a SAS statement Misspelling Omitting one quote ( ) in infile or title statement SAS Log will help you to find errors 31

Reading External Files data capm; * create the dataset capm; infile 'a:\table.txt'; * open the data file Table.txt; input x1 x2 m; * input the variables; proc print; var x1 x2 m; title 'CAPM Data'; run; * print; * variables; * print title; * run; 32