Section 3.9: RETAIN & sum statements –because all variables are set to missing at the start of each iteration of the DATA step, we need a statement to.

Slides:



Advertisements
Similar presentations
Copyright © 2006, SAS Institute Inc. All rights reserved. Think FAST! Use Memory Tables (Hashing) for Faster Merging Gregg P. Snell Data Savant Consulting.
Advertisements

The INFILE Statement Reading files into SAS from an outside source: A Very Useful Tool!
FORTRAN PROGRAMMING BASICS (2) MET 50. Programming Basics A few extra things from last week… 1. For a program written in Fortran 90, use the extension.
Some computer fundamentals and jargon Memory: Basic element is a bit – value = 0 or 1 Collection of “n” bits is a “byte” Collection of several bytes is.
I OWA S TATE U NIVERSITY Department of Animal Science Modifying and Combing SAS Data Sets (Chapter in the 6 Little SAS Book) Animal Science 500 Lecture.
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.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
Scripting Languages Chapter 6 I/O Basics. Input from STDIN We’ve been doing so with $line = chomp($line); Same as chomp($line= ); line input op gives.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
1 9/28/07CS150 Introduction to Computer Science 1 Loops section 5.2, 5.4, 5.7.
Programming with Collections Collections in Java Using Arrays Week 9.
CHAPTER 2 ANALYSIS OF ALGORITHMS Part 2. 2 Running time of Basic operations Basic operations do not depend on the size of input, their running time is.
Basic And Advanced SAS Programming
CS0007: Introduction to Computer Programming Introduction to Arrays.
Understanding SAS Data Step Processing Alan C. Elliott stattutorials.com.
CS1101: Programming Methodology Aaron Tan.
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.
PROC REPORT organizes the output in many ways, from the simple to highly complex… PROC REPORT NOWINDOWS HEADLINE HEADSKIP; COLUMN variable-list; DEFINE.
Introduction to SAS BIO 226 – Spring Outline Windows and common rules Getting the data –The PRINT and CONTENT Procedures Manipulating the data.
SAS SQL Part 2 Alan Elliott. Dealing with Missing Values Title "Dealing with Missing Values in SQL"; PROC SQL; select INC_KEY,GENDER, RACE, INJTYPE, case.
BMTRY 789 Lecture 3: Categorical Data and Dates Readings – Chapter 3 & 4 Lab Problems 3.1, 3.2, 3.19, 4.1, 4.3, 4.5 Homework – HW 2 Book Problems Due 6/24!
Learning to love the SAS LAG function Phuse 9-12 October 2011 Herman Ament, MSD, Oss NL Phuse 9-12 October 2011.
Math 3400 Computer Applications of Statistics Lecture 1 Introduction and SAS Overview.
SAS Macro: Some Tips for Debugging Stat St. Paul’s Hospital April 2, 2007.
SAS 介绍和举例 Presented by 经济实验教学中心 商务数据挖掘中心. Raw Data Read in Data Process Data (Create new variables) Output Data (Create SAS Dataset) Analyze Data Using.
SAS Efficiency Techniques and Methods By Kelley Weston Sr. Statistical Programmer Quintiles.
EPIB 698D Lecture 2 Raul Cruz Spring SAS functions SAS has over 400 functions, with the following general form: Function-name (argument, argument,
Lesson 2 Topic - Reading in data Chapter 2 (Little SAS Book)
Chapter 3 “Working With Your Data” concerns programming in the DATA step - putting lines of SAS code between a DATA and PROC statement… Creating new variables.
ISU Basic SAS commands Laboratory No. 1 Computer Techniques for Biological Research Animal Science 500 Ken Stalder, Professor Department of Animal Science.
Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS ESSENTIALS -- Elliott & Woodward1.
Summer SAS Workshop Lecture 2. Summer Summer SAS Workshop Lecture 2 I’ve got Data…how do I get started? Libname Review How do you do arithmetic.
Lesson 6 - Topics Reading SAS datasets Subsetting SAS datasets Merging SAS datasets.
Data Collections: Lists CSC 161: The Art of Programming Prof. Henry Kautz 11/2/2009.
Chapter 22: Using Best Practices 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 8 Arrays.
Select (drop-down list) Inputs. Insert/Form/List Menu.
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.
Arrays Chapter 13 How to do the following with a one dimensional array: Declare it, use an index.
Introduction to Perl. What is Perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Similar to shell script.
An Introduction Katherine Nicholas & Liqiong Fan.
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.
1 EPIB 698C Lecture 3 Raul Cruz-Cano Fall Creating and Redefining Variables You can create and redefine variables with assignment statements as.
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.
Use the SET statement to: –create an exact copy of a SAS dataset –modify an existing SAS dataset by creating new variables, subsetting (using a subsetting.
Week 6 - Friday.  What did we talk about last time?  Loop examples.
Lesson 2 Topic - Reading in data Programs 1 and 2 in course notes –Chapter 2 (Little SAS Book)
BMTRY 789 Lecture9: Proc Tabulate Readings – Chapter 11 & Selected SUGI Reading Lab Problems , 11.2 Homework Due Next Week– HW6.
Chapter 6: Modifying and Combining Data Sets  The SET statement is a powerful statement in the DATA step DATA newdatasetname; SET olddatasetname;.. run;
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
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 8, 13, & 24 By Tasha Chapman, Oregon Health Authority.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 16 & 17 By Tasha Chapman, Oregon Health Authority.
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.
Chapter 11 Reading SAS Data
Chapter 6: Modifying and Combining Data Sets
Have you signed up (or had) your meeting?
Chapter 3: Working With Your Data
Instructor: Raul Cruz-Cano
Strings, Line-by-line I/O, Functions, Call-by-Reference, Call-by-Value
Assume as previously that we have k samples on as many treatments
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.
Instructor: Raul Cruz-Cano 7/19/2012
Introduction to SAS Essentials Mastering SAS for Data Analytics
Presentation transcript:

Section 3.9: RETAIN & sum statements –because all variables are set to missing at the start of each iteration of the DATA step, we need a statement to override this... RETAIN does the job - it keeps the previous iteration’s value of whatever variable you list in the RETAIN statement –the sum statement is used to accumulate values of a variable... see example on p.93 Now use the RETAIN and sum statements to find the max. cost job and the total cost of all jobs for the data in section 3.5, p.85 - use retain maxcost; maxcost=max(maxcost,cost); totcost+cost;

DATA homeimprovements; INPUT Owner $ 1-7 Description $ 9-33 Cost; IF Cost =. THEN CostGroup = 'missing'; ELSE IF Cost < 2000 THEN CostGroup = 'low'; ELSE IF Cost < THEN CostGroup = 'medium'; ELSE CostGroup = 'high'; DATALINES; Bob kitchen cabinet face-lift Shirley bathroom addition Silvia paint exterior. Al backyard gazebo Norm paint interior Kathy second floor addition ; PROC PRINT DATA = homeimprovements; TITLE 'Home Improvement Cost Groups'; RUN;

Now let’s consider Arrays in SAS - there are two types: implicit and explicit... we’ll look at explicit only since they are the recommended type to use: –the ARRAY statement defines a set of variables (either all character or all numeric) so you may process them all at one time. An explicit array statement must contain a name for the array, a number that tells how many elements there are in the array, and a list of the elements (variables) in the array. –arrays are often processed in DO groups so that the same thing is done to all elements of the array. –See the example in section 3.10 on p –I is used as an index variable to refer to members of the array. I is incremented by 1 each time through the DO loop... –The array variables themselves do not become part of the DATA set, but I does

DATA songs; INPUT City $ 1-15 Age domk wj hwow simbh kt aomm libm tr filp ttr; *ratings on a scale of 1 to 5 for each of 10 songs; *missing values denoted by a 9 - not usual for SAS; *so create an array and replace 9 by. in each case; ARRAY song (10) domk wj hwow simbh kt aomm libm tr filp ttr; DO i = 1 TO 10; IF song(i) = 9 THEN song(i) =.; END; Albany Richmond Oakland Richmond Berkeley ; PROC PRINT DATA = songs; TITLE 'WBRK Song Survey'; RUN;

There are a couple of different ways to shortcut variable names in SAS –make your variables start with the same characters and end with consecutive numbers: a1, a2 a3,... a24; then you may abbreviate them as a1-a24 –if your variables are not set up as above, you may refer to consecutive ones with the double hyphen method: e.g., for INPUT x y r ca cb cc; you could then refer to these variables as : PROC PRINT; var y--cb; run; To find the internal order of variables in your dataset, use PROC CONTENTS POSITION; –there are a few special SAS name lists: _ALL_ refers to all the variables; _CHARACTER_ refers to all the character variables, and _NUMERIC_ refers to all the numeric variables in the dataset. (PUT _ALL_ and MEAN(of _NUMERIC_) are examples of how you might use these...)

Notice how these abbreviations are used in the example program on page 97: DATA songs; INPUT City $ 1-15 Age domk wj hwow simbh kt aomm libm tr filp ttr; ARRAY new (10) Song1 - Song10; ARRAY old (10) domk -- ttr; DO i = 1 TO 10; IF old(i) = 9 THEN new(i) =.; ELSE new(i) = old(i); END; AvgScore = MEAN(OF Song1 - Song10); DATALINES; Albany Richmond Oakland Richmond Berkeley PROC PRINT DATA = songs; TITLE 'WBRK Song Survey'; RUN;

Homework for Wednesday: –complete your reading of the textbook through Chapter 3 –look at the “oscars” dataset: read the excel data into SAS print it back out begin exploring this dataset using the various methods we’ve talked about so far: –SORTing and PRINTing; MEANS for the numeric variables as appropriate; FREQ for the categorical variables with crosstabulations as you think might be interesting… –we’ll talk about it some more on wednesday… this data will be part of your midterm