Lecture 5 Sorting, Printing, and Summarizing Your Data.

Slides:



Advertisements
Similar presentations
Statistical Methods Lynne Stokes Department of Statistical Science Lecture 7: Introduction to SAS Programming Language.
Advertisements

SAS Programming:File Merging and Manipulation. Reading External Files (review) data barf; * create the dataset BARF; infile ’s:\mysas\Table7.1'; * open.
Slide C.1 SAS MathematicalMarketing Appendix C: SAS Software Uses of SAS  CRM  datamining  data warehousing  linear programming  forecasting  econometrics.
A “LOTTO” SAS for you! or, “Check Your Balls with SAS Arrays” By Keith McWhorter Georgia Technology Authority January 30, 2007.
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.
SAS Programming: Working With Variables. Data Step Manipulations New variables should be created during a Data step Existing variables should be manipulated.
Introduction to SQL Session 1 Retrieving Data From a Single Table.
Basic And Advanced SAS Programming
Understanding SAS Data Step Processing Alan C. Elliott stattutorials.com.
Into to SAS ®. 2 List the components of a SAS program. Open an existing SAS program and run it. Objectives.
Creating SAS® Data Sets
Data Cleaning 101 Ron Cody, Ed.D Robert Wood Johnson Medical School Piscataway, NJ.
Topics in Data Management SAS Data Step. Combining Data Sets I - SET Statement Data available on common variables from different sources. Multiple datasets.
Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities.
Week 3 Topic - Descriptive Procedures Program 3 in course notes Cody & Smith (Chapter 2)
The New SAS Engine For CRSP   Benefits of using SAS engine for CRSP   Setting up the interface between SAS and CRSP   Examples of use   Performance.
I OWA S TATE U NIVERSITY Department of Animal Science Writing Flexible Codes with the SAS Macro Facility (Chapter in the 7 Little SAS Book) Animal Science.
Chapter 8 Producing Summary Reports. Section 8.1 Introduction to Summary Reports.
Chapter 9 Producing Descriptive Statistics PROC MEANS; Summarize descriptive statistics for continuous numeric variables. PROC FREQ; Summarize frequency.
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.
Chapter 21 Reading Hierarchical Files Reading Hierarchical Raw Data Files.
Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin.
1 Experimental Statistics - week 4 Chapter 8: 1-factor ANOVA models Using SAS.
Chapter 20 Creating Multiple Observations from a Single Record Objectives Create multiple observations from a single record containing repeating blocks.
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!
PREPARING DATA FOR STATISTICAL ANALYSIS Data Cleaning Data Cleaning Dataset Preparation Dataset Preparation Documentation Documentation 9 September 2008.
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.
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.
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.
1 Filling in the blanks with PROC FREQ Bill Klein Ryerson University.
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.
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 22: Using Best Practices 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Chapter 5 Reading and Manipulating SAS ® Data Sets and Creating Detailed Reports Xiaogang Su Department of Statistics University of Central Florida.
Chapter 4 concerns various SAS procedures (PROCs). Every PROC operates on: –the most recently created dataset –all the observations –all the appropriate.
1 EPIB 698C Lecture 4 Raul Cruz-Cano Summer 2012.
Summer SAS Workshop Lecture 3. Summer SAS Workshop Website
FOR MONDAY: Be prepared to hand in a one-page summary of the data you are going to use for your project and your questions to be addressed in the project.
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.
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.
HRP Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected by copyright law and.
BMTRY 789 Lecture 6: Proc Sort, Random Number Generators, and Do Loops Readings – Chapters 5 & 6 Lab Problem - Brain Teaser Homework Due – HW 2 Homework.
LISA SHORT COURSE SERIES: INTRODUCTION TO SAS UNIVERSITY William DeShong Fall 2015.
1 Introduction to SAS Available at
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.
Chapter 4: Creating List Reports
1 Data Manipulation (with SQL) HRP223 – 2009 October 12, 2009 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This.
Chapter 6: Modifying and Combining Data Sets  The SET statement is a powerful statement in the DATA step DATA newdatasetname; SET olddatasetname;.. run;
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
The Urban Institute - SAS Training6/9/20161 SAS Training This SAS Training Course was designed to introduce users at The Urban Institute to SAS programming.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 14 & 19 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.
Session 1 Retrieving Data From a Single Table
Applied Business Forecasting and Regression Analysis
Chapter 6: Modifying and Combining Data Sets
Instructor: Raul Cruz-Cano
Chapter 22 Reading Hierarchical Files
Chapter 4: Sorting, Printing, Summarizing
Quick Data Summaries in SAS
Presentation transcript:

Lecture 5 Sorting, Printing, and Summarizing Your Data

Review Creating and Redefining Variables SAS Functions IF-THEN Statements Grouping Observations with IF-THEN/ELSE Subsetting Data Simplifying Programs with Arrays

Lecture Structure Using SAS Procedures Printing Your Data with PROC PRINT Changing the Appearance of Printed Values with Formats Summarizing Your Data Using PROC MEANS

Using SAS Procedures LABEL ReceiveDate = 'Date order was received' ShipDate = 'Date merchandise was shipped';

Printing Your Data with PROC PRINT Use the NOOBS option in the PROC PRINT statement. If you don’t want observation numbers Print the labels instead of the variable names, then add the LABEL option as well. PROC PRINT DATA = data-set NOOBS LABEL; The following are optional statements that sometimes come in handy:

Printing Your Data with PROC PRINT DATA sales; INFILE 'D:\My Documents\My Class\TA\MyCode\05code and data\Candy.dat'; INPUT Name $ 1-11 DateReturned MMDDYY10. CandyType $ Quantity; Profit = Quantity * 1.25; PROC SORT DATA = sales; BY Class; PROC PRINT DATA = sales; BY Class; BY Class; SUM Profit; SUM Profit; VAR Name DateReturned CandyType Profit; VAR Name DateReturned CandyType Profit; TITLE 'Candy Sales for Field Trip by Class'; RUN; Adriana 21 3/21/2008 MP 7 Nathan 14 3/21/2008 CD 19 Matthew 14 3/21/2008 CD 14 Claire 14 3/22/2008 CD 11 Caitlin 21 3/24/2008 CD 9 Ian 21 3/24/2008 MP 18 Chris 14 3/25/2008 CD 6 Anthony 21 3/25/2008 MP 13 Stephen 14 3/25/2008 CD 10 Erika 21 3/25/2008 MP 17

Changing the Appearance of Printed Values with Formats CharacterNumericDate $formatw.formatw.dformatw. FORMAT statement FORMAT Profit Loss DOLLAR8.2 SaleDate MMDDYY8.; FORMAT statements can go in either DATA steps or PROC steps. If the FORMAT statement is in a DATA step, then the format association is permanent and is stored with the SAS data set. If the FORMAT statement is in a PROC step, then it is temporary— affecting only the results from that procedure. PUT statement PUT Profit DOLLAR8.2 Loss DOLLAR8.2 SaleDate MMDDYY8.;

Changing the Appearance of Printed Values with Formats Adriana 21 3/21/2008 MP 7 Nathan 14 3/21/2008 CD 19 Matthew 14 3/21/2008 CD 14 Claire 14 3/22/2008 CD 11 Caitlin 21 3/24/2008 CD 9 Ian 21 3/24/2008 MP 18 Chris 14 3/25/2008 CD 6 Anthony 21 3/25/2008 MP 13 Stephen 14 3/25/2008 CD 10 Erika 21 3/25/2008 MP 17 DATA sales; INFILE 'D:\My Documents\My Class\TA\MyCode\05code and data\Candy.dat'; INPUT Name $ 1-11 DateReturned MMDDYY10. CandyType $ Quantity; Profit = Quantity * 1.25; PROC PRINT DATA = sales; VAR Name DateReturned CandyType Profit; FORMAT DateReturned DATE9. Profit DOLLAR6.2; FORMAT DateReturned DATE9. Profit DOLLAR6.2; TITLE 'Candy Sale Data Using Formats'; RUN;

Summarizing Your Data Using PROC MEANS PROC MEANS options; If you do not specify any options, MEANS will print the number of non-missing values, the mean, the standard deviation, and the minimum and maximum values for each variable.

If you use the PROC MEANS statement with no other statements, then you will get statistics for all observations and all numeric variables in your data set. Here are some of the optional statements you may want to use: Summarizing Your Data Using PROC MEANS

/04/ /12/ /18/ /01/ /11/ /19/ /25/ A wholesale nursery is selling garden flowers, and they want to summarize their sales figures by month. The data file which follows contains the customer ID, date of sale, and number of petunias, snapdragons, and marigolds sold: DATA sales; INFILE 'D:\My Documents\My Class\TA\MyCode\05code and data\Flowers.dat'; INPUT CustomerID $ SaleDate MMDDYY10. Petunia SnapDragon Marigold; Month = MONTH(SaleDate); PROC SORT DATA = sales; BY Month; * Calculate means by Month for flower sales; PROC MEANS DATA = sales; BY Month; BY Month; VAR Petunia SnapDragon Marigold; VAR Petunia SnapDragon Marigold; TITLE 'Summary of Flower Sales by Month'; TITLE 'Summary of Flower Sales by Month'; RUN;

Exercise Download the dataset “Flowers.dat” from the folder “ 05 code and data” in our blackboard. Summarizing this dataset Using PROC MEANS by CustomerID. (This result does not need to submit. ) /04/ /12/ /18/ /01/ /11/ /19/ /25/ The data file which follows contains the customer ID, date of sale, and number of petunias, snapdragons, and marigolds sold: /* This is the Sample Code with red filled part*/ DATA dataname; INFILE ‘Locate your dataset here'; INPUT identify your data with right format; PROC function_name DATA = dataname; BY variable_name; VAR othervariable you want to show in your output;

Exercise Result DATA sales; INFILE 'D:\My Documents\My Class\TA\MyCode\05code and data\Flowers.dat'; INPUT CustomerID $ SaleDate MMDDYY10. Petunia SnapDragon Marigold; PROC SORT DATA = sales; BY CustomerID; * Calculate means by CustomerID, output sum and mean to new data set; PROC MEANS DATA = sales; BY CustomerID; VAR Petunia SnapDragon Marigold;