Introduction to SAS.ppt
《Introduction to SAS.ppt》由会员分享,可在线阅读,更多相关《Introduction to SAS.ppt(28页珍藏版)》请在麦多课文档分享上搜索。
1、Introduction to SAS,Statistical Computing for Research Kyra Robinson March 1, 2012,Rationale for SAS,“Quick” analysis for collaborative work Output is generally preferable to that output by R The corporate and regulatory world usually prefers or even requires SAS versus “non-validated” software such
2、 as R Can often check results using R Remember, R is object oriented; SAS is not. Cons include SAS debatably inferior graphics, though they have recently improved drastically!,03/01/2012,2,Introduction to SAS,Collaborative Work,As biostatisticians (or epidemiologists), we usually prefer to be involv
3、ed in collaborative efforts from the study design phaseHowever, many times, we do not get involved until the investigators have collected data and/or already attempted to analyze the data (unsuccessfully)What do we do?,03/01/2012,3,Introduction to SAS,Getting Data into SAS,We first must get the data
4、 into a format we can work with in SAS! Most common approach: SAS Import Wizard Click-and-point method Can request output of PROC IMPORT code into another destination file (to be used to import same data again later) Can use INFILE statement in DATA step Could also write your own PROC IMPORT code, i
5、f desired,03/01/2012,4,Introduction to SAS,Import Wizard,03/01/2012,Introduction to SAS,5,The Basics of SAS: Data Steps and PROCS,Data steps Create new datasets, modify datasets, add/delete variables, merge/stack datasets, subset, generate random numbers from specified distributionPROCs (Procedures)
6、 SORT, MEANS, UNIVARIATE, GPLOT, REG, CORR, FREQ, TTEST, ANOVA, NPAR1WAY, MIXED, GLM, GENMOD, LOGISTIC, GLIMMIX,03/01/2012,Introduction to SAS,6,Libraries,Libraries give us a way to permanently store datasets Must be assigned before we can call the library (“libname” statement) Called by “library.”
7、before data name Example: libname kyraslibrary “C:UsersKyraDocumentsMUSCTHESIS_research“; DATA kyraslibrary.simdata; . 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,03/01/2012,Introduction to SAS,7,Libraries-c
8、ontd,Libraries can be really helpful, especially when we dont want to re-import data each time we run a program. Example: My simulations take about 3.5 hours to construct a dataset for each scenario. I dont want to have to make this dataset every time! Be careful with permanent datasets that have pr
9、edefined formats: Use “OPTIONS FMTSEARCH=(mylib);” outside of PROC and DATA steps Creating permanent formats must be done with PROC FORMAT,03/01/2012,Introduction to SAS,8,Formats,Formatting data values Examples YES/NO is oftentimes coded as 1/0 in databases 1,2,3 may correspond to mild, moderate, a
10、nd severe Syntax:PROC FORMAT LIBRARY=mylib; *creates permanent formats;VALUE fmtgender 0=male1=female;RUN; Calling formats in the DATA step DATA kyraslib.example; *make the dataset a permanent dataset in my library; set example; format gender fmtgender.; RUN;,03/01/2012,Introduction to SAS,9,Helpful
11、 Hints,Dates (see p.124 of Cody and Smith): MMDDYY8., MMDDYY10. Note that dates are tricky (read as numeric values, # days from 01/01/1960) Labels can be used to make variable names more meaningful DROP or KEEP statements can be used at the end of the DATA step to narrow down the number of variables
12、 in a dataset WHERE can also help subset data Note that the default character length is 8, but this can be overridden with INFORMAT myvar $20.; (or some other length, or myvar: $20. in the input statement),03/01/2012,Introduction to SAS,10,Getting Data Out of SAS,Just like SAS has an Import Wizard f
13、or other file types, it also has an Export Wizard. Can export SAS datasets as other types of files Excel, CSV, etc. Can request SAS to output the PROC EXPORT code it uses (for future use) Again, can use PROC EXPORT if you desire,03/01/2012,Introduction to SAS,11,Export Wizard,03/01/2012,Introduction
14、 to SAS,12, vs. : Helpful Knowledge,Placing at the end of the INPUT statement allows for multiple observations per line Placing after a variable allows for a logic statement for that variable Example:DATA WEIGHT;INFILE ;INPUT GENDER$ ;IF GENDER = M THEN DELETE;INPUT WEIGHT AGE;RUN;,03/01/2012,Introd
15、uction to SAS,13,Conditional Operators,IF . THEN . ELSE IF THEN ELSE . LT, GT, =, NE, LE, GE Be careful with missing values:IF AGE NE . THEN DO;IF AGE LT 18 THEN DELETE;END;,03/01/2012,Introduction to SAS,14,Useful Functions,LOG: base e (natural log) LOG10: base 10 SIN, COS, TAN, ARSIN, ARCOS, ARTAN
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- INTRODUCTIONTOSASPPT