An Introduction Katherine Nicholas & Liqiong Fan.

Slides:



Advertisements
Similar presentations
Haas MFE SAS Workshop Lecture 3:
Advertisements

Summary Statistics/Simple Graphs in SAS/EXCEL/JMP.
Technology Short Courses: Spring 2010 Kentaka Aruga
Axio Research E-Compare A Tool for Data Review Bill Coar.
The SAS ® System Additional Information on Statistical Analysis Programming.
Statistical Methods Lynne Stokes Department of Statistical Science Lecture 7: Introduction to SAS Programming Language.
Slide C.1 SAS MathematicalMarketing Appendix C: SAS Software Uses of SAS  CRM  datamining  data warehousing  linear programming  forecasting  econometrics.
Knowing Understanding the Basics Writing your own code part 2 SAS Lab.
Introduction to SAS Programming Christina L. Ughrin Statistical Software Consulting Some notes pulled from SAS Programming I: Essentials Training.
How to enter data in SPSS
Introduction to SPSS Allen Risley Academic Technology Services, CSUSM
Today: Run SAS programs on Saturn (UNIX tutorial) Runs SAS programs on the PC.
Introduction to SQL Session 1 Retrieving Data From a Single Table.
SPSS 1: An Introduction to the Statistical Package SPSS Suzie Cro MRC Clinical Trials Unit.
Chapter 18: Modifying SAS Data Sets and Tracking Changes 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Understanding SAS Data Step Processing Alan C. Elliott stattutorials.com.
Creating SAS® Data Sets
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.
Collection and Analysis of Data CPH 608 Spring 2015.
SAS SQL SAS Seminar Series
SAS PROC REPORT PROC TABULATE
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.
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.
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 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.
Knowing Understanding the Basics Writing your own code SAS Lab.
Chapter 1: Introduction to SAS  SAS programs: A sequence of statements in a particular order  Rules for SAS statements: –Every SAS statement ends in.
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.
Introduction to Enterprise Guide Jennifer Schmidt Rhonda Ellis Cassandra Hall.
1 EPIB 698E Lecture 1 Notes Instructor: Raul Cruz 7/9/13.
1 Data Manipulation (with SQL) HRP223 – 2010 October 13, 2010 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This.
Laboratory 1. Introduction to SAS u Statistical Analysis System u Package for –data entry –data manipulation –data storage –data analysis –reporting.
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.
SAS Basics. Windows Program Editor Write/edit all your statements here. Log Watch this for any errors in program as it runs. Output Will automatically.
Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS Essentials - Elliott & Woodward1.
Chapter 1: Overview of SAS System Basic Concepts of SAS System.
Summer SAS Workshop Lecture 3. Summer SAS Workshop Website
Lesson 8 - Topics Creating SAS datasets from procedures Using ODS and data steps to make reports Using PROC RANK Programs in course notes LSB 4:11;5:3.
SAS Basics. Windows Program Editor Write/edit all your statement here.
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.
Customize SAS Output Using ODS Joan Dong. The Output Delivery System (ODS) gives you greater flexibility in generating, storing, and reproducing SAS procedure.
HRP Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected by copyright law and.
1 PEER Session 02/04/15. 2  Multiple good data management software options exist – quantitative (e.g., SPSS), qualitative (e.g, atlas.ti), mixed (e.g.,
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;
1 EPIB 698C Lecture 1 Instructor: Raul Cruz-Cano
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
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 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.
Session 1 Retrieving Data From a Single Table
Chapter 6: Modifying and Combining Data Sets
SAS Programming Introduction to SAS.
ECONOMETRICS ii – spring 2018
Chapter 1: Introduction to SAS
Tamara Arenovich Tony Panzarella
Chapter 4: Sorting, Printing, Summarizing
SAS Basics: Statement and Data Set
Data Manipulation (with SQL)
Presentation transcript:

An Introduction Katherine Nicholas & Liqiong Fan

Outline Basics Getting Data Into SAS Data Steps Procs Saving Datasets and Stats Homework

Basics: The Windows 4 main windows : ▫The editor window is for programming. ▫The log allows you to monitor the execution of your program.  Red -> error  Blue -> generally means you’re good, but watch out for “ observations read”  No print in log: proc printto log="nul:"; run; ods listing close;  Options symbolgen mlogic mprint mfile; ▫The output window shows the results of your procs and will generally be unchanged by data steps.  Supress output in output windows: noprint ▫The results viewer window displays results from procs in html format. Version 9.3 always uses this window instead of the output window, but it can be called in any version with an ods html statement.

Basics: The Windows 2 secondary windows: ▫ Explorer shows existing SAS folders and libraries.  Your datasets will be in Work unless your have specified a different library. ▫ Results is like a table of contents for the output/results viewer window (depending on which version you are using).

Libraries Libraries give us a way to permanently store datasets Must be assigned before we can call the library (“libname” statement) Called by “library.” before data name ▫Example: libname valid "C: \Users\Liqiong\Desktop\PUDS\SAS Datasets"; DATA valid.ims3;..... RUN; If no library is specified, all data is stored in the default WORK library ▫This library is temporary and is cleared when SAS closes

Getting Data Into SAS 3 ways: ▫Manual input ▫Infile ▫Proc import (program or use the drop down menu) Issues to Consider: ▫Character $ verses Numeric Variables  Once in SAS, variables can be converted back and forth with put and input.  Syntex: ▫Newvar = Put(oldvar, format) ▫Formats: $length  Using characters under numeric environment ▫Format of the data  Temporary VS. permanent

Data Steps: Set, Sort, and Merge I can copy a dataset or append one dataset to another with set. ▫This will effect the number of observations/rows. However, if I want to combine information from the same subjects, I need to use merge. ▫This will effect the number of variables/columns. ▫I need a unique identifier to be present in both datasets to merge them, and I have to pre-sort on this.

Data Steps: Creating Variables and Drop/Keep New variables can be exact copies of existing variables or functions thereof. Functions of missing variables are missing. Syntax: newvar=function(existingvar) Useful fucntions: ▫mean() ▫sum() ▫int() We can choose to retain all of our variables, keep only the important ones, or drop those that we no longer need.

Useful Functions: LOG: base e (natural log) LOG10: base 10 SIN, COS, TAN, ARSIN, ARCOS, ARTAN INT: drops fractional part of number SQRT: square root ROUND(X,.1), ROUND(X,1), ROUND(X,100) MEAN(A,B,C); MEAN(OF X1-X5) ▫Careful with missing values ▫MIN, MAX, SUM, STD, STDERR, N, NMISS, ABS CEIL(), FLOOR() UPCASE(), LOWCASE() FIRST., IN()

Data step: Create several datasets within one data step Example data all trt (keep = id trt age) ctl (keep = id trt medication) set complete;. output all; if trt = 1 then output trt; if trt = 0 then output ctl; run;

Data Steps: Do Loops Do loops are very helpful if you want to perform operations on only certain subsets of observations, or if the operation that you want to do depends on the data in some way. They are very helpful for iterative processes like simulation or numerical approximation algorithms. Every do loop must be closed by an end statement. Loops within loops are allowed and often necessary.

Data Steps: If/Then Conditional statements can be used to manipulate data in a data step. Syntax: if condition then action; else if condition then action; else action; Rules: ▫I can use and/or in the condition, but not in the action ▫If there are multiple if/then statements in a single data step, previous statements can be overwritten by later ones. This can be avoided with else if. ▫Be careful of missing values. ▫Where can be used if you only have one condition to specify. Useful commands: ▫lt or < ▫gt or > ▫le or <= ▫ge or >= ▫eq or = ▫not eq or not =

Other procedures: proc sql Very helpful command Syntex: PROC SQL options; SELECT column(s) FROM table-name | view-name WHERE expression GROUP BY column(s) HAVING expression ORDER BY column(s); QUIT; Example: proc sql; create table ct4 as select *, min(abs(time)) as pick from ct3 group by subjectid having abs(time) = calculated pick; quit;

Procs Any canned procedure in SAS is called a proc. Commonly used procs include: ▫sort ▫freq ▫means ▫univariate ▫ttest ▫reg ▫logistic ▫anova ▫glm ▫mixed ▫glimmix ▫gplot Syntax is different depending on which proc you are using and can be found in the online SAS Useful Statements: ▫By (to do stratified analyses) ▫Class (for categorical variables) ▫Var (for continuous variables) ▫Output (to save data for later)

Saving Dataset and Stats: Labels and Formats Before we can give data or results to others, we need to make sure that the format is meaningful. The label= options changes the name assigned to a variable and can be used in a data step or proc. ▫Syntax: var(label=“name”) Rename variables: rename ▫Syntax: rename old = new; The format statement can be used to change the labels associated with the actual values of a variable.

Formatting data values Examples ▫YES/NO is oftentimes coded as 1/0 in databases ▫1,2,3 may correspond to ‘mild,’ ‘moderate,’ and ‘severe’ Syntax: PROC FORMAT LIBRARY=mylib; *creates permanent formats; VALUE fmtgender 0=‘male’ 1=‘female’; RUN; Calling formats in the DATA step DATA example; *make the dataset a permanent dataset in my library; set example; format gender fmtgender.; RUN; Use “OPTIONS FMTSEARCH=(mylib);” outside of PROC and DATA steps for predefined data format

Saving Datasets and Stats: Dates A value that represents the number of days between January 1, 1960, and a specified date Always be sure to format your dates in SAS as they are particularly troublesome. Example: “14686” date9. and it returns the form “17MAR2000”. Some helpful Functions for working with dates: ▫day() ▫month() ▫year() ▫datepart() ▫substr() Good website for reference of SAS data format:

Exporting Datasets and Stats: Exporting As many of your investigators will not have SAS, you will also need to be able to export your data into other forms including: ▫.xls (excel) ▫.txt (text file) ▫.csv (works for most software) The export wizard is very easy to use, but proc export is also available.

Exporting Datasets and Stats: ODS Output can also be formatted and saved for later use with the ODS statement. Some file types include: ▫.rtf ▫.pdf ▫.html You can also specify a style with the style= option; file = “” option. More on ODS graphics later.

Homework Two data sets: Subject: ID, gender (1=“male”), treatment (1=“treatment”), age Score: ID, Total NIHSS score, time of evaluation What you need to do: ▫Divide subjects into 4 groups based on the order of subject ID (i.e. 25 subjects per group) ▫Test the distribution of gender is the same between treatments ▫Create 5 data sets:  Only male or female  Only subjects having largest total NIHSS score within each group  Only subjects having closest evaluation time within each group  Output data set from proc freq procedure: cell count and percent, row percent, column percent, test statistic and P-value for the Chi-squared test.