Here’s another problem (see section 2.13 on page 54). A file contains two different types of records (say A’s and B’s) and we only want to read in the.

Slides:



Advertisements
Similar presentations
The SAS ® System Additional Information on Statistical Analysis Programming.
Advertisements

The INFILE Statement Reading files into SAS from an outside source: A Very Useful Tool!
A guide to the unknown…  A dataset is longitudinal if it tracks the same type of information on the same subjects at multiple points in time or space.
Introduction to Computing Science and Programming I
Statistics in Science  Introducing SAS ® software Acknowlegements to David Williams Caroline Brophy.
XP New Perspectives on Microsoft Office Excel 2003, Second Edition- Tutorial 11 1 Microsoft Office Excel 2003 Tutorial 11 – Importing Data Into Excel.
Pasewark & Pasewark 1 Access Lesson 6 Integrating Access Microsoft Office 2007: Introductory.
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.
Creating SAS® Data Sets
Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities.
§IV 3:30 - 4:30PM: Data - The various sources, qualities, and metrics: What do you need to know before you can take it to the model? Copyright 2014 Institute.
SAS Workshop Lecture 1 Lecturer: Annie N. Simpson, MSc.
Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS ESSENTIALS -- Elliott & Woodward1.
NA-MIC National Alliance for Medical Image Computing shapeAnalysisMANCOVA_Wizar d Lucile Bompard, Clement Vacher, Beatriz Paniagua, Martin.
1 MySQL and phpMyAdmin. 2 Navigate to and log on (username: pmadmin)
PROC REPORT organizes the output in many ways, from the simple to highly complex… PROC REPORT NOWINDOWS HEADLINE HEADSKIP; COLUMN variable-list; DEFINE.
4/22/2017 5:36 PM EViews Training Creating Workfiles.
General Programming Introduction to Computing Science and Programming I.
Chapter 20 Creating Multiple Observations from a Single Record Objectives Create multiple observations from a single record containing repeating blocks.
Using Advanced INPUT Techniques Peter Cosette Dave Hall Amy Dunn-Ruiz Eric Lyon.
SAS Macro: Some Tips for Debugging Stat St. Paul’s Hospital April 2, 2007.
SAS Efficiency Techniques and Methods By Kelley Weston Sr. Statistical Programmer Quintiles.
Use the UPDATE statement to: –update a master dataset with new transactions (e.g. a bank account updated regularly with deposits and withdrawals…). Not.
EPIB 698C Lecture 2 Notes Instructor: Raul Cruz 2/14/11 1.
Bringing Data into SAS From Menu: –File –Import Data –Spreadsheet example first Pick file by browsing Select Library and Member (we will talk about this.
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.
Chapter 17 Creating a Database.
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.
Working With Files. Sources of Data Adding data to a spreadsheet can be done in several ways, including: – Type it in piece by piece – Read it from a.
1 Data Manipulation (with SQL) HRP223 – 2010 October 13, 2010 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This.
BMTRY 789 Lecture 11: Debugging Readings – Chapter 10 (3 rd Ed) from “The Little SAS Book” Lab Problems – None Homework Due – None Final Project Presentations.
CCS – Mail Merge Mail Merge This presentation is incomplete without the associated discussion 1 Coloma Community Schools In-service 21 March 2014.
Using Text Files in Excel File I/O Methods. Working With Text Files A file can be accessed in any of three ways: –Sequential access: By far the most common.
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
Chapter 4 concerns various SAS procedures (PROCs). Every PROC operates on: –the most recently created dataset –all the observations –all the appropriate.
Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS Essentials - Elliott & Woodward1.
YET ANOTHER TIPS, TRICKS, TRAPS, TECHNIQUES PRESENTATION: A Random Selection of What I Learned From 15+ Years of SAS Programming John Pirnat Kaiser Permanente.
1 Statistical Software Programming. STAT 6360 –Statistical Software Programming Data Input in SAS Many ways to get your data into SAS: –Through data entry.
CSD 340 (Blum)1 Starting JavaScript Homage to the Homage to the Square.
Files Tutor: You will need ….
HRP Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected by copyright law and.
Controlling Input and Output
Lecture 4 Ways to get data into SAS Some practice programming
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.
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.
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,
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.
HRP Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected by copyright law and.
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.
1 EPIB 698C Lecture 1 Instructor: Raul Cruz-Cano
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
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.
By Sasikumar Palanisamy
Lesson 2 Topic - Reading raw data into SAS
Introduction to SAS®.
Instructor: Raul Cruz-Cano 7/9/2012
Chapter 2: Getting Data into SAS
Chapter 4: Sorting, Printing, Summarizing
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.
Click ‘browse’ to search your device for
Introduction to Computer Science
Presentation transcript:

Here’s another problem (see section 2.13 on page 54). A file contains two different types of records (say A’s and B’s) and we only want to read in the A’s... there are a number of ways to do this, but an easy way is given on p. 54 using the so-called : DATA XXXX; INPUT TYPE IF TYPE=“B” THEN DELETE; INPUT other variables for the A record; See the program on the next page...

freeway surface Martin Luther King Jr. Blvd surface Broadway surface Rodeo Dr freeway freeway surface Lake Shore Dr surface Pennsylvania Ave * Use a to delete surface streets; DATA freeways; INFILE 'c:\MyRawData\Traffic.dat'; INPUT Type IF Type = 'surface' THEN DELETE; INPUT Name $ 9-38 AMTraffic PMTraffic; PROC PRINT DATA = freeways; TITLE 'Traffic for Freeways'; RUN;

Note there are two INPUT statements; the first one reads the value of TYPE and the IF … THEN statement performs the test; if the value of TYPE is “surface”, then the second INPUT statement never executes; instead SAS returns to the beginning of the DATA step to process the next observation. Look at the log to check this out… See the last paragraph on page 55: –the holds the data line for subsequent INPUT statements but releases the line when SAS returns to the top of the DATA step –the holds for subsequent INPUT statements even when SAS starts building a new observation

There are other ways of controlling the way we input data when using the INFILE statement (these are options with INFILE) –FIRSTOBS= This tells SAS the line on which to begin reading from the file. I use this a lot when I’ve placed a “counter” on line #1 to count columns- then use FIRSTOBS=2 –OBS= This option tells SAS the line on which to end the reading from the file. Most often used to limit the number of observations read into the SAS dataset; e.g., if you have a huge dataset and you want to test your code on a small portion of the data. Can also be used with FIRSTOBS= to choose a subset of data between the value of FIRSTOBS and the value of OBS. –MISSOVER This option is used to help deal with missing data that happen to occur at the end of the dataline; i.e., don’t go to the next line if you run out of data. Go over the example on p. 57 to see how it works. –TRUNCOVER This option tells SAS to read data until it gets to the end of the line or the last column specified in the column input range, whichever comes first; i.e., it’s used when you’re using column input and some data lines are shorter than others. See example, p. 57

*Put this data in c:\MyRawData\Scores.dat; *NOTE that Nguyen and Robbins have incomplete data...; Nguyen Ramos Robbins SAS program - try it both with and without the MISSOVER statement to see what will happen in each case… DATA class102; INFILE 'c:\MyRawData\Scores.dat' MISSOVER; INPUT Name $ Test1 Test2 Test3 Test4 Test5; RUN;

*Put this data in c:\MyRawData\Address.dat; *NOTE that the addresses are diffent lengths...; John Garcia 114 Maple Ave. Sylvia Chung 1302 Washington Drive Martha Newton 45 S.E. 14th St. SAS program - try it both with and without the TRUNCOVER statement to see what will happen in each case… DATA homeaddress; INFILE 'c:\MyRawData\Address.dat' TRUNCOVER; INPUT Name $ 1-15 Number Street $ 22-37; RUN;

A file is delimited if it is a raw datafile that uses special characters to separate (or delimit) the individual values of the variables... Examples of delimiters are commas, tabs, etc. Use the INFILE statement with the DLM= option to handle this situation: –DLM=‘,’ will tell SAS that the file is comma- delimited –DLM=‘09’x will tell SAS that the file uses the tab character to delimit values of the variables. (09 is the hexadecimal representation of tab)

Grace,3,1,5,2,6 Martin,1,2,4,1,3 Scott,9,10,4,8,6 Can be read with: DATA reading; INFILE ‘C:\MYRAWDATA\BOOKS.DAT’ DLM=‘,’; INPUT NAME $ Week1-Week5; RUN; QUIT; But what about missing values? 2 Commas in a row? Use the DSD option (Delimited Separated Data) in the INFILE statement as seen in the following: INFILE ‘C:\MYRAWDATA\XXXX.DAT’ DLM=‘,’ DSD;

DSD does 3 things: –ignores delimiters inside data values enclosed in quotes –does not read quotes as part of the data –treats two delimiters in a row as a missing value NOTE: DSD assumes the delimiter is a comma - If it’s not, be sure to use the DLM option along with DSD… CSV files are a type of file written by Excel and the DSD option will read them… CSV files use comma as delimiter and two commas in a row for missing value… Let’s try an example...

Look at the file co2.csv, consisting of the countries of the world with population at least 20 million. The values of the co2 variable are the number of metric tons of co2 emissions per person in each of the corresponding countries. Open it with Notepad to see it in text form Two ways to proceed: –first use the INFILE statement with the appropriate options (DLM=‘,’ DSD) to read the CSV version of the Excel file. If you have an EXCEL.xls file, you may save it as.csv. –a second possibility is to use the IMPORT option under the File menu to read the Excel file directly into SAS. Let’s try this method next… HW:Make sure you’ve completely read and worked through the examples (skip )