Presentation is loading. Please wait.

Presentation is loading. Please wait.

The SAS ® System Additional Information on Statistical Analysis Programming.

Similar presentations


Presentation on theme: "The SAS ® System Additional Information on Statistical Analysis Programming."— Presentation transcript:

1 The SAS ® System Additional Information on Statistical Analysis Programming

2 Getting Data into SAS ® Other ways to read data

3 Getting Data into SAS ® Four General Categories: Create SAS data set from raw data files This is what we’ve been doing so far Enter directly into SAS data set Convert other software’s data files into SAS data sets Read other software’s data files directly

4 Getting Data into SAS ® CAUTION! Why are ASCII and Text files better to work with? Because they’re permanent! Most other ways that you can read data into SAS data sets are temporary – they last while your session is open They must be converted into permanent data sets to be reused later Data are easily lost

5 Getting Data into SAS ® Raw data files: The DATA step is versatile enough to read almost any type of raw data file (ASCII, Text) Internal, External, List files, Columns, Non- standard (dates, dollars, etc.) Import Wizard reads particular types of raw data files like comma-separated values (CSV), and other delimited files Can also import from Excel and Access

6 Getting Data into SAS ® Import Wizard: File Menu  Import Data Select the type of data (Excel, Access, Comma Delimited, Tab Delimited) Next, choose the location of the file you want to import

7 Getting Data into SAS ® Import Wizard: Choose a SAS library (WORK is temporary, save in other to keep) Name the data set (“Member”) Last window gives you the option to save the PROC IMPORT commands

8 Getting Data into SAS ® If you’re not going to modify the data in any way, you can run procedures with the DATA command specifying where your data set is SAS library.File name

9 Getting Data into SAS ® To read the data into a program, start with the “IMPORT” commands that you saved, then add your program SAS library.file name Original File Type of File

10 Getting Data into SAS ® Entering Data Directly with Viewtable Window The “Viewtable” window will let you both view & modify existing SAS data sets as well as create new SAS data sets Displays SAS data sets (also called “tables”) in a tabular view

11 Getting Data into SAS ® Viewtable window Tools Menu  Table Editor Start typing & SAS will determine numeric v. character data, or Right click on a letter (column) & choose “Column Attributes”

12 Getting Data into SAS ® Viewtable window Enter your data Save your data: File menu  Save As… Either select an existing library, or create a new library Name your file (‘Member Name’)

13 Getting Data into SAS ® If you’re not going to modify the data in any way, you can run direct DATA commands

14 Getting Data into SAS ® Now, to read the data into a program, you use an “INFILE” statement with the location of the file you created

15 Getting Data into SAS ® Reading Other Software’s Data Files Directly In most cases, SAS/ACCESS for PCs will allow you to directly import Excel, Lotus, and dBase You use the IMPORT procedure, and add a “DBMS” code for the type of data: PROC IMPORT DATAFILE = ‘filename’ OUT = data-set DBMS = identifier REPLACE;

16 Getting Data into SAS ® For Excel, Lotus, and dBase files Type of FileExtensionDBMS Identifier Microsoft Excel.xlsEXCEL* EXCEL5 EXCEL4 Lotus.wk4WK4.wk3WK3.wk1WK1 dBase.dbfDBF *The same identifier is used for Excel, Excel2002, Excel2000, Excel97

17 Getting Data into SAS ®

18 To read Access files, instead of DATAFILE, you use TABLE and DATABASE PROC IMPORT TABLE = ‘table-name’ OUT = data-set DBMS = identifier REPLACE; DATABASE = ‘database-path’ Type of FileExtensionDBMS Identifier Microsoft Access.mdbACCESS* ACCESS97 *The same identifier is used for Access, Access2002, Access2000

19 Other Useful Things Arrays, correction commands, etc.

20 Array Statements Sometimes you want to do the same thing to many variables. Instead of writing a long series of IF statements, you can build an array In SAS, an array is a group of variables They need to be all numeric or all character ARRAY name (n) variable-list;

21 Array Statements Next, you tell SAS what you want it to do to this group of variables by creating a ‘DO Loop’ (everything between DO and END) ARRAY name (n) variable-list; DO code; IF something THEN something; END;

22 Array Statements This array changes all values of “9” (refused) to missing data for the four variables in the array

23 Means You may want to calculate a mean response value for two cross-tabbed variables What was the mean response for the question on parking for people in each age category?

24 Correcting a Data Error If you find that data has been incorrectly entered into the data set, rather than correcting it in the ASCII set, add a command to the SAS program Tells the program that before running anything else, it must change the value for ‘age’ in id #123 to 35

25 Create a Random Number List Sometimes you need to randomly select cases from your dataset to work with for analysis or assessment purposes SAS can generate a random number list for you This example creates 25 random numbers

26 The SAS ® System There’s really not much you can’t do in the way of working with data sets in SAS Just a matter of learning the right code and a little trial and error!


Download ppt "The SAS ® System Additional Information on Statistical Analysis Programming."

Similar presentations


Ads by Google