DOC PREVIEW
UI STAT 5400 - Introduction to SAS

This preview shows page 1-2 out of 5 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

22S:166Computing in StatisticsIntroduction to SASLect 17Oct. 14, 2009Kate Cowles374 SH, [email protected]• SAS is the statistical software package most com-monly used in business, government, and manyother applied research settings– has the best data management capabilities– can handle huge datas ets– not as user-friendly or well-designed as R orS-PLUS in some other ways– R or S-PLUS are often preferred for researchin theoretical and methodological statistics• preparing data for analysis usually takes moretime and work than doing the actual analysis2Two ways to run SAS• batch mode– use text edito r to write a file containing SAScode– extension “.sas”; e.g. filename might by “conadp.sas”– run it in batch mode by entering “sas <filename>”;e.g. “sas conad p”– SAS produces two new output files∗ log file with .log extension∗ output file with .lst extension• interactive mode– just enter “sas”– program editor, log, and output are three win-dows– online help available3How SAS programs and commands are or-ganized• Use a DATA step to organize your data by cre-ating a SAS dataset.• Then use PROC steps to analyze your data usingSAS procedures.– Once you have created a SAS dataset, youmay apply any SAS procedures t o it duringthe current SAS session without recreating thedataset.• DATA and PROC steps consis t of SAS s tate-ments.– Each statement must end with a semicolon.– Most statements include one or more keywordsthat must be spelled exactly as shown.4The DATA step: Creating a SAS datasetBefore it can process data, SAS must read in the datain the form of a table with• a row for each observation• a column for each variableYou must choose a name for the entire dataset and aname for each variable.SAS distinguishes between two types of variables:• numeric variables, which contain only digits anddecimal points and with which arithmetic ope ra-tions may be done• character variables (all other kinds of data).5SAS data step• data statement– must begin the data step– gives name by which to refer to datas et duringthis SAS run• infile statement– tells SAS in what physical file to find data– may optionally give SAS information about fileand how to read it6• input statement– gives names to all variables– variables are assum ed to be numeric unless youput a $ after name in input statement– may contain informats (goes after variable nameto which it applies)– may contain @ <column-number> (goes beforevariable name to which it applies)• may contain additional statements– formats for printing values of variables– calculating new variables– etc.• to embed data right into the SAS program, datalinesstatement is used instead of in fi le• ends with run statement7Starting SAS in different environments• Running SAS in the ITCClick on Start/All Programs/SAS/SAS 9.1 (En-glish). SAS will come up, but it will be runningon the university’s “Virtual Desktop,” not on yourlocal computer. That means that SAS will not beable to find files on the local drives. It should beable to find files in your H: drive, however.You can ac ces s SAS on the university’s “VirtualDesktop” from other Windows computers, includ-ing from home. Go to itc.uiowa .eduand select “Virtual Desktop” on the left panel.• Running SAS on the Linux networkThe Division of Mathematical Sciences has a SASlicence for only one of the computers on the Linuxnetwork. If you type ”sas” at the Linux prompt,you will automatically be logged into that com-puter (you will be prompted for your password).SAS will come up in interactive mode.8To make Linux SAS work more like Windows SAS,do the following:• Select the Program Editor window.• Click ”Tools” and ”Options,” and select ”Prefer-ences”• Click the ”Toolbox” tab and DEPRESS the threetoggles (Display Tools Window, Dis play CommandWindow, Combine Windows)• Click the ”Editing” tab and UNPRESS the toggle”Automatically store selection”• Click ”OK”9Entering commands and programsHowever you access SAS, you will get a screen thatshows:• a menu bar• a log window• a program editor windowClick in the program editor window. You m ay nowtyp e commands and programs i n this window.10How SAS programs and commands are or-ganizedUse a DATA step to organize your data by creatinga SAS dataset. Then use PROC steps or automatedfeatures to analyze your data. Once you have createda SAS datas et , you may apply any SAS proceduresor automated features to it during the SAS sessionwithout recreating the dataset.DATA and PROC steps consist of SAS statements.Each statement must end with a semicolon. Moststatements include one or more keywords that mustbe spelled exactly as s hown.11The DATA step: Creating a SAS datasetBefore it can process data, SAS must read in the datain the form of a table with• a row for each observation• a column for each variableYou must choose a name for the entire dataset and aname for each variable. SAS has the following rulesfor names:• SAS names must begin with a letter or an under-score. The remaining characters in a SAS namecan be letters, numbers, or underscores. Theremust be no embedded blanks.SAS distinguishes between two types of variables:numeric variables, which contain only digits anddecimal points and with which arithmetic operationsmay be done, and character variables (all other kindsof data).12Controlling print widthPut this line at the beginning of every SAS programif you want output to print correctly on 8-1/2 by 11inch paper:options linesize = 75 ;13Reading data in from an existing datafileSuppos e you have saved the file “billion.dat” in adirectory called SASdata on your H: drive. Use an“infile” statement to tell SAS to use it.data billion ; * gives dataset a name for SASinfile ’h:\my documents\SASdata\billion.dat’ ; * tells SAS where the data isinput wlth age region $ ; * names the variables in each row* $ after region identifies character vblrun ; * end of data step14Using datalinesAlternatively, you may use a datalines state-ment instead of an infile statement, andcopy and paste the data directly into thedata step. This wil l avoi d any issues withmapping local drives to virtual drives. Youmust put a semicolon on a line by itself af-ter the last row of data. This would looklike:data billion ; * gives dataset a name for SASinput wlth age region $ ; * names the variables in each row* $ after


View Full Document

UI STAT 5400 - Introduction to SAS

Documents in this Course
Load more
Download Introduction to SAS
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Introduction to SAS and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Introduction to SAS 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?