Introduction to SAS for Data Analysis - The University of ... Workshop and the SAS programming language, or Base SAS. ... Introduction to SAS for Data Analysis UNCG Quantitative Methodology Series | 20 DATA DATA:

Download Introduction to SAS for Data Analysis - The University of ...  Workshop   and the SAS programming language, or Base SAS. ... Introduction to SAS for Data Analysis UNCG Quantitative Methodology Series | 20 DATA DATA:

Post on 06-Mar-2018

221 views

Category:

Documents

8 download

Embed Size (px)

TRANSCRIPT

  • IntroductiontoSASforDataAnalysis

    UNCGQuantitativeMethodologySeries|1

    IntroductiontoSASforDataAnalysis

    ScottRichterTheUniversityofNorthCarolinaatGreensboro

  • IntroductiontoSASforDataAnalysis

    UNCGQuantitativeMethodologySeries|2

    Contents1 WhatisSAS?.........................................................................................................................................3

    2 What can I do with SAS?......................................................................................................................4

    3 FindingSAS............................................................................................................................................5

    3.1 UNCGfaculty,stafforstudents........................................................................................................5

    3.2 OutsidetheUNCSystem...................................................................................................................6

    3.3 SASCodingandSyntax......................................................................................................................7

    3.4 GettingdataintoSAS......................................................................................................................20

    4 StatisticalanalysisusingSAS...............................................................................................................21

    4.1 Ourworkingdataset......................................................................................................................21

    4.2 Researchquestions.........................................................................................................................24

    4.3 UsingSAStogettheresults............................................................................................................29

    4.4 SASEnterpriseGuide......................................................................................................................66

  • IntroductiontoSASforDataAnalysis

    UNCGQuantitativeMethodologySeries|3

    1 WhatisSAS?From:http://www.sas.com/en_us/companyinformation.html

    SASistheleaderinanalytics.Throughinnovativeanalytics,businessintelligenceanddatamanagementsoftwareandservices,SAShelpscustomersatmorethan80,000sitesmakebetterdecisionsfaster.Since1976,SAShasbeengivingcustomersaroundtheworldTHEPOWERTOKNOW.

    Inthisworkshop,wewilllearnthebasicsofusingSASforstatisticalanalysis,including Datafilecreation/acquisition Datamanipulation Usingsuppliedfunctions Simpledataanalysesandgraphics Wewillonlyscratchthesurface!

  • IntroductiontoSASforDataAnalysis

    UNCGQuantitativeMethodologySeries|4

    2 What can I do with SAS? SAS is an integrated software suite for advanced analytics, business intelligence, data management, and predictive analytics. You can use SAS software through both a graphical interface and the SAS programming language, or Base SAS.

    With SAS software, you can

    access data in almost any format, including SAS tables, Microsoft Excel tables, and database files.

    manage and manipulate your existing data to get the data that you need. For example, you can subset your data, combine it with other data, and create new columns.

    analyze your data using statistical techniques ranging from descriptive measures like correlations to logistic regression and mixed models to sophisticated methods such as modern model selection and Bayesian hierarchical models.

    present the results of your analyses in a meaningful report that you can share with others. The reports that you create can be saved in a wide variety of formats, including HTML, PDF, and RTF.

  • IntroductiontoSASforDataAnalysis

    UNCGQuantitativeMethodologySeries|5

    3 FindingSAS3.1 UNCGfaculty,stafforstudentshttp://its.uncg.edu/software/available/sas/SAS and JMP may be installed on a University (desktop or laptop) computer, or used on a home computer by faculty, staff or students enrolled in degree-granting programs at UNCG.

    How can I get the software?

    Install from the campus network. SAS and JMP are available for installation on university-owned computers at no charge from Run Advertised Programs (RAP). For details on installing software from RAP please see Installing Applications on the General Computing Network.

    Download SAS installation files via secure FTP. You can download the SAS or JMP installation files via secure FTP from any location with internet access. For this option you will need high-speed internet and no data download limits. Please note: Because the SAS installation files are over 15GB in size the download will take a significant amount of time - at 1mbps download, you can expect the download to take over 4 hours. For instructions visit: Secure FTP download instructions for SAS.

    Assisted installation in the TSC. Consultants in the Technology Support Center in 101 Forney Building on campus can download and/or install SAS for free to your 32G or higher flash drive, external hard drive, or computer.

    Install from disc. Installation discs may be borrowed from the ITS Client Services office in 202 Forney for a refundable deposit of $5. Office hours are 8am-5pm, M-F, except on university holidays. Outside of office hours, you can call 6-TECH at 336-256-8324 to request the disc and get instructions on how to pick it up.

    Use the versions installed on the campus network SAS is available in the ITS open access computer labs and from either on or off campus via MyCloud.

  • IntroductiontoSASforDataAnalysis

    UNCGQuantitativeMethodologySeries|6

    3.2 OutsidetheUNCSystem

    SAS University Edition WithSASUniversityEdition,yougetSASStudio,BaseSAS,SAS/STAT,SAS/IML,SAS/ACCESSandseveraltimeseriesforecastingproceduresfromSAS/ETS.It'sthesameworldclassanalyticssoftwareusedbymorethan80,000business,governmentanduniversitysitesaroundtheworld,including93ofthetop100companiesontheFortuneGlobal500list.Thatmeansyou'llbeusingthemostuptodatestatisticalandquantitativemethods.Anddidwementionit'sfree?(http://www.sas.com/en_us/software/universityedition.html)

  • IntroductiontoSASforDataAnalysis

    UNCGQuantitativeMethodologySeries|7

    3.3 SASCodingandSyntaxStartusingSASfromlabmachine.FromtheSTARTmenufindtheSASfolderunderAllProgramsandchooseSAS9.3(or9.4).Somethingsimilartobelowappears:

    SASWindows

    1. (Enhanced)EditorAlthoughtherearenowotherwaystoobtainresultsinSAS,the

    traditionalmethodistocomposeandexecuteprogramsintheeditorwindow.Hereiswhereyouwillwriteyourprograms.

    2. LogContainsthedetailsofprogramexecution.TheLogwindowiswheretolooktofinderrors,warningsandinformationonsettings.OnstartuptheLogwindowgivesversionandlicensinginformation.

    3. OutputContainsoutputgeneratedbytheprogram.Note:Beginninginversion9.3,theResultsWindow,containingoutputinhtmlformat,openswheneveroutputisgeneratedratherthantextoutput.

    4. Results/ExplorerTheResultswindowwillcontainalistofoutputcreated,andtheExplorerwindowallowsfunctionsinasimilarwaytoWindowsExplorer.

  • IntroductiontoSASforDataAnalysis

    UNCGQuantitativeMethodologySeries|8

    Composingaprogram SASrequiresthatacompletemoduleofcodebeexecutedinordertocreateandmanipulatedatafilesandperformdataanalysis.Ingeneral,firstadatafilemustbecreatedusingaDATAstep.TheDATAstep. ThereareseveralwaystocreatedatafilesinSAS,butthesimplestistolisttheobservationswithinaDATAstep.Example.Supposeahavealistavaluesforwhichwewishtocomputesummarystatistics.*Program 1: First DATA step;data first_data; input y; datalines; 2 5 9 9 10 11 ; run; ThefirstlineopenstheDATAstepandnamesthefile.Theinputstatementspecifiesthevariablenames.datalinestellsSAStoexpectthedatapointstobelisted,startingonthenextrow.TherunstatementendstheDATAstep.SASwillreadthecommandsbutwillnotexecuteanyuntilarunstatementisencountered.

  • IntroductiontoSASforDataAnalysis

    UNCGQuantitativeMethodologySeries|9

    Submittingcode.Thereareatleastthreewaystosubmitaprogram:

    i.ChooseSubmitfromtheRunmenu.

    ii.Clickontherunningmanicon, ,intheApplicationToolbar.

  • IntroductiontoSASforDataAnalysis

    UNCGQuantitativeMethodologySeries|10

    iii.TypeSubmitintheCommandwindowintheupperleftcornerofthewindow.

    Whenthiscodeissubmitted,thefollowingappearsintheLogwindow:

  • IntroductiontoSASforDataAnalysis

    UNCGQuantitativeMethodologySeries|11

    1 *Program 1: First DATA step (p.8); 2 data first_data; 3 input y; 4 datalines; NOTE: The data set WORK.FIRST_DATA has 6 observations and 1 variables. NOTE: DATA statement used (Total process time): real time 0.13 seconds cpu time 0.00 seconds 11 ; 12 run;

    Asstatedonp.7,theLoggivesdetailsofprogramexecutionandalsodisplayserrorsandwarnings.Inthiscase,itindicatesthattheSASdatafileWORK.FIRST_DATA has been created. The WORK prefix indicates the SAS folder where the data file is stored. It can be viewed using the Explorer window: Double-clicking the Libraries icon opens a list of SAS folders, including the Work folder.

  • IntroductiontoSASforDataAnalysis

    UNCGQuantitativeMethodologySeries|12

    InsidetheWorkfolderistheFirst_datafile:

  • IntroductiontoSASforDataAnalysis

    UNCGQuantitativeMethodologySeries|13

    DoubleclickingonFirst_dataopenstheVIEWTABLE:

  • IntroductiontoSASforDataAnalysis

    UNCGQuantitativeMethodologySeries|14

    ThedatafilecanalsobeviewedintheResultswindowusingthePRINTprocedure.Thecodebelowcanbesubmittedasbefore.Theoptiondata=datafilenameappearsafteraspaceafterprocprint.Otheroptions,separatedbyaspace,mayalsobeaddedasnecessary:*Program 2: Printing the data file; proc print data=first_data; run;TheResultswindow(s)then