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.

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.
Knowing Understanding the Basics Writing your own code part 2 SAS Lab.
SAS Programming: Working With Variables. Data Step Manipulations New variables should be created during a Data step Existing variables should be manipulated.
Today: Run SAS programs on Saturn (UNIX tutorial) Runs SAS programs on the PC.
1 Creating and Tweaking Data HRP223 – 2010 October 24, 2011 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This.
Quick Data Summaries in SAS Start by bringing in data –Use permanent data set for these examples Proc Tabulate –Produces summaries very quickly and easily.
1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR, etc. The most.
1 Computer Applications in Epidemiology Dongmei Li Lecture 26 5/6/2009.
SW318 Social Work Statistics Slide 1 Using SPSS for Graphic Presentation  Various Graphics in SPSS  Pie chart  Bar chart  Histogram  Area chart 
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.
Data Cleaning 101 Ron Cody, Ed.D Robert Wood Johnson Medical School Piscataway, NJ.
Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities.
Lecture 5 Sorting, Printing, and Summarizing Your Data.
SAS Workshop Lecture 1 Lecturer: Annie N. Simpson, MSc.
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.
1 Experimental Statistics - week 4 Chapter 8: 1-factor ANOVA models Using SAS.
Introduction to SAS. What is SAS? SAS originally stood for “Statistical Analysis System”. SAS is a computer software system that provides all the tools.
PREPARING DATA FOR STATISTICAL ANALYSIS Data Cleaning Data Cleaning Dataset Preparation Dataset Preparation Documentation Documentation 9 September 2008.
Lesson 5 - Topics Formatting Output Working with Dates Reading: LSB:3:8-9; 4:1,5-7; 5:1-4.
Quantify the Example Data First, code and quantify the data (assign column locations & variable names) Use the sample data to create a data set from the.
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.
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.
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.
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.
Introduction to Enterprise Guide Jennifer Schmidt Rhonda Ellis Cassandra Hall.
A Simple Guide to Using SPSS ( Statistical Package for the Social Sciences) for Windows.
1 EPIB 698E Lecture 1 Notes Instructor: Raul Cruz 7/9/13.
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.
Priya Ramaswami Janssen R&D US. Advantages of PROC REPORT -Very powerful -Perform lists, subsets, statistics, computations, formatting within one procedure.
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.
Lecture 3 Topic - Descriptive Procedures Programs 3-4 LSB 4:1-4.4; 4:9:4:11; 8:1-8:5; 5:1-5.2.
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.
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.
1 Statistical Software Programming. STAT 6360 –Statistical Software Programming Sorting, Printing, Summarizing Data Now that we can input data and do.
Chapter 1: Overview of SAS System Basic Concepts of SAS System.
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.
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.
Chapter 17 Supplement: Alternatives to IF-THEN/ELSE Processing STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South.
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.
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.
SAS Programming Training Instructor:Greg Grandits TA: Textbooks:The Little SAS Book, 5th Edition Applied Statistics and the SAS Programming Language, 5.
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 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.
Applied Business Forecasting and Regression Analysis
Chapter 2: Getting Data into SAS
Instructor: Raul Cruz-Cano
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.
Quick Data Summaries in SAS
Producing Descriptive Statistics
Presentation transcript:

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 –if FORMAT is used in a PROC step, then the formats are temporary and are not in play after that PROC executes… PUT statements are used to write data to a file or to write reports & formats can be used (along with other pointer controls) within the PUT … try this with the data on page 109

DATA sales; INFILE 'c:\MyRawData\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; SUM Profit; VAR Name DateReturned CandyType Profit; FORMAT DateReturned DATE9. Profit DOLLAR6.2; TITLE 'Candy Sales for Field Trip by Class'; FOOTNOTE ‘USING FORMATS’ ; RUN;

DATA FOR THE PREVIOUS SLIDE Adriana 21 3/21/2000 MP 7 Nathan 14 3/21/2000 CD 19 Matthew 14 3/21/2000 CD 14 Claire 14 3/22/2000 CD 11 Caitlin 21 3/24/2000 CD 9 Ian 21 3/24/2000 MP 18 Chris 14 3/25/2000 CD 6 Anthony 21 3/25/2000 MP 13 Stephen 14 3/25/2000 CD 10 Erika 21 3/25/2000 MP 17 USE THIS DATA TO WRITE THE NAME, QUANTITY SOLD AND PROFIT (IN DOLLAR FORMAT) TO A TEXT FILE NAMED CANDYOUT.TXT - try this…. PUT PROFIT DOLLAR8.2;

This doesn’t do the job… the PUT statement without a FILE statement writes in the LOG window… So add the following in the DATA step (can go after the INFILE for example…) FILE ‘path to file goes here’; Check out section 4.6 on pages for a small list of the standard formats that SAS uses… If the FORMAT you want is not available you may write your own with PROC FORMAT;

PROC FORMAT creates your own formats that can later be associated with output through the use of a FORMAT statement (don’t forget the end “dot” when they are actually used) The syntax requires one or more VALUE statements after the beginning PROC FORMAT statement. The VALUE statements give names for the formats (name must begin with $ if format is for character data) and tell what values of the variable will be associated with the formats: PROC FORMAT; VALUE name range = “format value” … ; Character values being formatted must be in quotes. Ranges of values can be indicated in several ways (see bottom of p. 112)…

PROC FORMAT; VALUE $island ‘si’=‘Shell Island’ ‘ph’ = ‘Pizza Hut’; VALUE mass 0 - < 5 = ‘small’ 5-high = ‘large’; NOTE: For each variable in SAS there is: a construct the variable “measures” a name you give to the variable the values of the variable You may change the name for outputting with LABEL You may change the values for outputting with FORMAT (either SAS built-in ones or ones you write yourself with PROC FORMAT) See the example from p. 113:

DATA carsurvey; INPUT Age Sex Income Color $; datalines; Y G B Y W PROC FORMAT; VALUE gender 1 = 'Male' 2 = 'Female'; VALUE agegroup 13 -< 20 = 'Teen' 20 -< 65 = 'Adult' 65 - HIGH = 'Senior'; VALUE $col 'W' = 'Moon White' 'B' = 'Sky Blue' 'Y' = 'Sunburst Yellow' 'G' = 'Rain Cloud Gray'; PROC PRINT DATA = carsurvey; FORMAT Sex gender. Age agegroup. Color $col. Income DOLLAR8.; run; quit;

PROC MEANS options; Other possible statements with PROC MEANS are: –BY varible-list; (makes MEANS do separate analyses for each level of vars. in the list; dataset must be SORTed by the variables in the list) –CLASS variable-list; (makes MEANS do as with BY, but has more compact output; dataset does not have to be SORTed) –VAR variable-list; (makes MEANS only operate on the variables in the list; if VAR statement is not there, then all numeric variables are analyzed) Show the difference between BY and CLASS

PROC MEANS may be used to create new datasets with the OUTPUT statement; these new datasets contain the resulting statistics (mean, sum, etc.) by doing the PROC MEANS. The following example creates a new dataset (named STATS) containing the means and standard deviations of the mass and height variables from both marshes: PROC MEANS DATA=padgett; BY MARSH; OUTPUT OUT=stats MEAN(totmass plantht)=massmean htmean STD(totmass plantht)=masssd htsd; run; Go over the example on page 119 for another look at this important method of creating new datasets in SAS…

PROC FREQ does frequency distributions for single variables and cross tabulations for two or more variables together… –TABLES varible-combinations ; is a required statement –the * between two variables creates a variable combination and signals that a cross tabulation is to be done. –options may be added to PROC FREQ by listing them after a slash (/) in the TABLES statement. Some key options for PROC FREQ are: LIST which prints cross tabulations in list format instead of tabular form MISSING includes missing values in the distributions (and hence in the computations) NCOL and NROW supresses the printing of the column and row percentages respectively in cross tabulations OUT=dataset_name; creates a dataset of frequencies. –TRY THESE OUT ON PADGETT DATA…

For Wednesday: –Read Chapter 4 up through 4.7, –HW: 1. write a series of PROC FORMATs so we may better understand the oscars dataset (e.g., gender, born in u.s., etc…); test them out and then send me the file with your SAS code… 2. try out the new results for PROCs MEANS and FREQ on the same dataset… –Be prepared to work on reporting: using the PUT statement along with FILE (4.8) using PROC TABULATE ( ) using PROC REPORT ( ) –Start looking for your own dataset to analyze for the midterm …