欢迎来到麦多课文档分享! | 帮助中心 海量文档,免费浏览,给你所需,享你所想!
麦多课文档分享
全部分类
  • 标准规范>
  • 教学课件>
  • 考试资料>
  • 办公文档>
  • 学术论文>
  • 行业资料>
  • 易语言源码>
  • ImageVerifierCode 换一换
    首页 麦多课文档分享 > 资源分类 > PPT文档下载
    分享到微信 分享到微博 分享到QQ空间

    Introduction to SAS.ppt

    • 资源ID:376713       资源大小:218.13KB        全文页数:28页
    • 资源格式: PPT        下载积分:2000积分
    快捷下载 游客一键下载
    账号登录下载
    微信登录下载
    二维码
    微信扫一扫登录
    下载资源需要2000积分(如需开发票,请勿充值!)
    邮箱/手机:
    温馨提示:
    如需开发票,请勿充值!快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如需开发票,请勿充值!如填写123,账号就是123,密码也是123。
    支付方式: 支付宝扫码支付    微信扫码支付   
    验证码:   换一换

    加入VIP,交流精品资源
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    Introduction to SAS.ppt

    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

    16、 INT: drops fractional part of number SQRT: square root ROUND(X, .1), ROUND(X,1), ROUND(X,100) MEAN(A,B,C); MEAN_X=MEAN(OF X1-X5) Careful with missing values MIN, MAX, SUM, STD, STDERR, N, NMISS,03/01/2012,Introduction to SAS,15,Date and Time Functions, FYI,MDY(month, day, year): converts to a SAS d

    17、ate YRDIF(early date, later date, ACTUAL): Computes # of years from early to later date ACTUAL tells SAS to factor in leap years and days of months NOTE that a SAS date constant is represented by ddMMMyyyyD (15MAY2004D) YEAR, MONTH, DAY (from 1 to 31 returned), WEEKDAY (1 to 7), HOUR, MINUTE, SECOND

    18、 INTCK(interval, start, end) Returns number of intervals Interval may be DAY, WEEK, MONTH, QTR, YEAR, HOUR, MINUTE, SECOND INTNX(interval,start,# intervals) Returns a date See Cody and Smith for more helpful information,03/01/2012,Introduction to SAS,16,Converting Numeric Character,PUT() converts nu

    19、meric variables to character variables Newvar = PUT(oldvar, format) Formats: $length. INPUT() converts character variables to numeric variables Newvar = INPUT(oldvar, format) Formats: length.length Note: COMPRESS(var, delim) can take away things like dashes in Social Security Numbers: COMPRESS(SS, -

    20、),03/01/2012,Introduction to SAS,17,Remember the “$” signifies character variables in SAS,Random Number Generation,x = ranuni(seed) /* uniform between 0 /* random from (1,2,3) with probs */* p1,p2,p3 */,03/01/2012,Introduction to SAS,18,Example,Example of sample from Uniform DATA UNIFORM;DO i = 1 TO

    21、 100;uni=RANUNI(0); OUTPUT;END; Do loops are often useful: DO var = TO ; DO var = .; DO WHILE (); evaluated before loop DO UNTIL (); evaluated after loop Must finish with END, and OUTPUT ensures that new value created after each loop run Seed should be 0 (uses clock to generate sequence) or positive

    22、 integer Seed is important for replicating results!,03/01/2012,Introduction to SAS,19,Arrays (Overview),Arrays can provide a convenient way to process multiple variables at once. One common use of arrays is converting datasets from long to short form, and vice versa PROC TRANSPOSE can also be used f

    23、or this Personally, I prefer arrays Arrays are the topic of another lecture, so I will limit our discussion to the basics. See handout for more about TRANSPOSE and arrays,03/01/2012,Introduction to SAS,20,Arrays-contd,Declaring arrays in the DATA step: DATA NEW; SET OLD; ARRAY x5 x1-x5; * Can also b

    24、e ARRAY x5 A B C D E DO i = 1 to 5 IF xi = 999 THEN xi = .; *convert 999 code to missing; End; DROP i; RUN:If we use _NUMERIC_ (and x*) after array declaration, all numeric variables will have the new conversion _CHARACTER_ can also be used, but $ must be placed after array name,03/01/2012,Introduct

    25、ion to SAS,21,Arrays Example: Short to Long,Suppose we have the following dataset, and we want to convert this dataset to one with multiple observations per ID:,03/01/2012,Introduction to SAS,22,Use the following SAS Code:,*CONVERT TO MULTIPLE OBSERVATIONS PER SUBJECT;DATA MULTIPLE; SET SINGLE; ARRA

    26、Y SCORE_ARRAY3 SCORE1-SCORE3;/*Score1 is stored in Score_Array1, etc*/ DO TIME = 1 TO 3; SCORE=SCORE_ARRAYTIME; /*Score1-Score3 are each stored in the SCORE variable in order*/ *IF SCORE NE . THEN OUTPUT; OUTPUT; /*After each time value, output score*/ END; KEEP ID TIME SCORE; /*Only keep the variab

    27、les we want*/ RUN;,03/01/2012,Introduction to SAS,23,Output Delivery System,While there is another lecture on ODS, I thought I would briefly show you (or remind you) about some of the ODS basics. Can make .rtf, .pdf, html files that are much easier to read than the output window Ideal for getting ou

    28、tput into reports or homework assignments This is very simple to doODS PDF FILE=“pdf”; -Whatever you want in the file-ODS PDF CLOSE;,03/01/2012,Introduction to SAS,24,List of Styles,Default Journal Statistical Analysis Astronomy Banker BarrettsBlue Beige BlockPrint Brick Brown Curve D3d Education El

    29、ectronics FancyPrinter Gears Magnify Minimal Money NoFontDefault Printer RSVP RTF SansPrinter SASDocPrinter SASWeb Science SerifPrinter Sketch StatDoc Theme Torn Watercolor,03/01/2012,Introduction to SAS,25,Examples at http:/stat.lsu.edu/SAS_ODS_styles/SAS_ODS_styles.htm,Other Fun ODS Things,ODS GRA

    30、PHICS Makes pretty diagnostic plots (perhaps default in 9.3?) Proc Reg ODS TRACE ON/LISTING; Able to store SAS created objects as your own datasets ods listing close; * turns off output display; proc means; var x; ods output summary=sum1; run; ods listing; * turns it back on; http:/ http:/ to SAS,26,Lets work through some examples!,03/01/2012,Introduction to SAS,27,Questions?,Thank you! If you have any questions later, stop by and see me or email me at robinskmmusc.edu,03/01/2012,Introduction to SAS,28,


    注意事项

    本文(Introduction to SAS.ppt)为本站会员(吴艺期)主动上传,麦多课文档分享仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知麦多课文档分享(点击联系客服),我们立即给予删除!




    关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

    copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
    备案/许可证编号:苏ICP备17064731号-1 

    收起
    展开