SAS Basics. Windows Program Editor Write/edit all your statement here.

Slides:



Advertisements
Similar presentations
Axio Research E-Compare A Tool for Data Review Bill Coar.
Advertisements

The INFILE Statement Reading files into SAS from an outside source: A Very Useful Tool!
Statistical Methods Lynne Stokes Department of Statistical Science Lecture 7: Introduction to SAS Programming Language.
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.
S ORTING WITH SAS L ONG, VERY LONG AND LARGE, VERY LARGE D ATA Aldi Kraja Division of Statistical Genomics SAS seminar series June 02, 2008.
Knowing Understanding the Basics Writing your own code part 2 SAS Lab.
Statistics in Science  Introducing SAS ® software Acknowlegements to David Williams Caroline Brophy.
SAS Programming: Working With Variables. Data Step Manipulations New variables should be created during a Data step Existing variables should be manipulated.
Some Terms Y =  o +  1 X Regression of Y on X Regress Y on X X called independent variable or predictor variable or covariate or factor Which factors.
1 SAS Formats and SAS Macro Language HRP223 – 2011 November 9 th, 2011 Copyright © Leland Stanford Junior University. All rights reserved. Warning:
SAS BASICS Technology Short Courses: Fall 2009 Kentaka Aruga.
Permanent Formats and Working Across Platforms. 32bit vs. 64 bit SAS The different versions of SAS optimize datasets and formats to work as fast as possible.
Basic And Advanced SAS Programming
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.
EPLS Lab Software Orientation SAS. Orientation Overview Background Getting Started SAS Windows.
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.
Introduction to SAS Lecture 2 Brian Healy.
Creating SAS® Data Sets
Topics in Data Management SAS Data Step. Combining Data Sets I - SET Statement Data available on common variables from different sources. Multiple datasets.
SAS Workshop Lecture 1 Lecturer: Annie N. Simpson, MSc.
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.
HPR Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected by copyright law and.
1 Experimental Statistics - week 2 Review: 2-sample t-tests paired t-tests Thursday: Meet in 15 Clements!! Bring Cody and Smith book.
SAS Efficiency Techniques and Methods By Kelley Weston Sr. Statistical Programmer Quintiles.
Knowing Understanding the Basics Writing your own code SAS Lab.
SAS lecture - week 31 Some Basics of CQUEST The operating system in the ESC lab (1046) is Linux. The operating system in RW labs (107/109 and 211) is Windows.
EPIB 698C Lecture 2 Notes Instructor: Raul Cruz 2/14/11 1.
Chapter 1: Introduction to SAS  SAS programs: A sequence of statements in a particular order  Rules for SAS statements: –Every SAS statement ends in.
01/20151 EPI 5344: Survival Analysis in Epidemiology SAS code and output February 24, 2015 Dr. N. Birkett, School of Epidemiology, Public Health & Preventive.
Grant Brown.  AIDS patients – compliance with treatment  Binary response – complied or no  Attempt to find factors associated with better compliance.
ISU Basic SAS commands Laboratory No. 1 Computer Techniques for Biological Research Animal Science 500 Ken Stalder, Professor Department of Animal Science.
1 Filling in the blanks with PROC FREQ Bill Klein Ryerson University.
1 EPIB 698E Lecture 1 Notes Instructor: Raul Cruz 7/9/13.
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.
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.
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.
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.
Chapter 17: Formatting Data 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
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.
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.
Lecture 4 Ways to get data into SAS Some practice programming
An Introduction Katherine Nicholas & Liqiong Fan.
14b. Accessing Data Files in SAS ®. 1 Prerequisites Recommended modules to complete before viewing this module  1. Introduction to the NLTS2 Training.
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.
Multiple Imputation using SAS Don Miller 812 Oswald Tower
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.
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
Lesson 2 Topic - Reading in data Programs 1 and 2 in course notes –Chapter 2 (Little SAS Book)
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
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 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 2: Getting Data into SAS
Chapter 1: Introduction to SAS
Tamara Arenovich Tony Panzarella
Discriminant Analysis
File Sharing and Processing Grouped Data
Introduction to SAS Lecturer: Chu Bin Lin.
Hans Baumgartner Penn State University
Presentation transcript:

SAS Basics

Windows Program Editor Write/edit all your statement here.

Windowscontinue … Log Watch this for any errors in program as it runs

Windowscontinue … Output Will automatically pop in front when there is output. Does not need to occupy screen space during program editing.

File Organization Create subfolders in your Project folder for Data Contains SAS datasets, with.sd2 extension Formats Compiled version of formats, a file with.sc2 extension. Used for building classes of variables for looking at frequencies. Output Save output files here. These are text files with a.sas extension. Programs All programs are text files with.sas ending.

Creating a dataset Internal Data DATA datasetname; INPUT name $ sex $ age; CARDS; John M 23 Betty F 33 Joe M 50 ; RUN;

Creating a dataset External Data DATA datasetname; INFILE ‘ c:\folder\subfolder\file.txt ’ ; INPUT name $ sex $ age; ; RUN;

Creating from an existing one DATA save.data2 (keep = age income); SET save.data1; RUN; DATA save.data2; SET save.data1; DROP age; TAX = income*0.28; RUN;

Permanent Data Sets LIBNAME save ‘ c:\project\data ’ ; DATA save.data1; X=25; Y=X*2; RUN; Note that save is merely a name you make up to point to a location where you wish to save the dataset called data1. (It will be saved as data1.sd2)

What ’ s in my SAS dataset ? PROC CONTENTS data=save.data1; RUN; PROC CONTENTS data=save.data1 POSITION; RUN; This will organize the variable list sorted alphabetically and a duplicate list sorted by position (the sequence in which they actually exist in the file).

Viewing file contents PROC PRINT data=save.data1; run; PROC PRINT data=save.data1 (obs=5); VAR name age; RUN; PROC PRINT data=save.data1 (obs=12); VAR age -- income; RUN;

Frequencies/Crosstabs PROC FREQ data=save.data1; TABLES age income trades; RUN; PROC FREQ data=save.data1; TABLES age*sex; RUN;

Scatter Plot PROC PLOT data=save.data1; PLOT Y*X; RUN;

Creating a Format Library PROC FORMAT LIBRARY=LIBRARY; VALUE BG 0 = 'BAD' 1 = 'GOOD' -1 = 'MISSING' ; VALUE TWO -1 = 'MISSING' -2 = 'NO RECORD' -3 = 'INQS. ONLY' -4 = 'PR ONLY' 0='0' 1='1' 1<-HIGH='2+' ; RUN;

Applying a format to a variable PROC DATASETS library=save; MODIFY data1; FORMAT trades ten.; RUN; QUIT; This applies the format called ten to the variable trades. A subsequent PROC FREQ statement for trades will show the format applied. Note that ten must already exist in the format library for this to work.

Applying a format: Method 2 Data save.data2; SET save.data1; FORMAT trades bktrds ten. totbal mileage. ; RUN; This is another way to apply formats when creating a new dataset (data2) from a previous one (data1) that has unformatted variables.

Random Selection of Obs. DATA save.new; SET save.old; Random1 = RANUNI(254987)*100; IF Random1 > 50 THEN OUTPUT; RUN; QUIT; The function RANUNI requires a seed number, and then produces random values between 0 and 1, stored under the variable name Random1 (you can choose any name). The above program will create new.sd2, with about half the observations of old.sd2, randomly chosen.

Sorting and Merging Datasets PROC SORT data = save.junk; BY Age Income; Run; PROC SORT data=save.junk OUT=save.neat; BY acctnum; RUN; PROC SORT data=save.junk NODUPKEY; BY something; RUN;

Sorting and Merging Datasets PROC SORT data=save.one; BY Acctnum; RUN; PROC SORT data=save.two; BY Acctnum; RUN; DATA save.three; MERGE save.one save.two; BY Acctnum; RUN;

Sorting and Merging Datasets DATA save.three; MERGE save.one (IN = a) save.two; BY Acctnum; IF a; RUN;

Using Arrays DATA save.new; SET save.old; ARRAY vitamin(6) a b c d e k; DO i = 1 to 6; IF vitamin(i) = -5 THEN vitamin(i) =.; END; RUN; This assumes you have 6 variables called a, b, c, d, e, and,k in save.old. This program will modify all 6 such that any instance of a – 5 value is converted to a missing value.

Simple Correlations PROC CORR data=save.relative; VAR tvhours study; RUN; PROC CORR data=save.relative; VAR tvhours study; WITH Score; RUN;

Run Regression Analysis Runs the regression and stores the estimates in a file called estfile Proc reg data=save.treg2 corr outest=estfile; bgscore: model good= trades01 trades02 ageavg01 ageavg02 / selection=none; run; Quit;

Score the data Score the data intreg1 and save the output in save.scrdata Proc score data=save.treg1 score=estfile out=save.scrdata type=parms; trades01 trades02 ageavg01 ageavg02 Run; Quit;

Format bgscore Format the bgscore variable in the new save.scrdata file. Find or create a format from the format.sas file to apply to the bgscore variable. Proc datasets library=save; Modify scrdata; Format bgscore insert_format_here.; Run; Quit;

Creating Dummy Variables %MACRO DUMMY(VAR, FIRST, LAST, TOT); IF(&FIRST <= &VAR <= &LAST) THEN &VAR.&TOT =1; ELSE &VAR.&TOT =0; LABEL &VAR.&TOT="&VAR: &FIRST - &LAST "; %MEND DUMMY; data save.testreg2; set save.testreg; %Dummy(AGEOTD, 0, 78, 1); %Dummy(AGEOTD, 96, 119, 2); %Dummy(AGEOTD, 120, 143, 3); %Dummy(AGEOTD, 144, 179, 4); %Dummy(AGEOTD, 180, , 5); Run; Quit;