Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 2 Getting Data into SAS Directly enter data into SAS data sets –use the ViewTable window. You can define columns (variables) with the Column Attributes.

Similar presentations


Presentation on theme: "Chapter 2 Getting Data into SAS Directly enter data into SAS data sets –use the ViewTable window. You can define columns (variables) with the Column Attributes."— Presentation transcript:

1 Chapter 2 Getting Data into SAS Directly enter data into SAS data sets –use the ViewTable window. You can define columns (variables) with the Column Attributes window (see p.32) –or use SAS/FSP (Full Screen Product)... maybe later Enter data into text files and then read it into SAS data sets text file = ASCII = “raw” data. Convert other software’s datasets into SAS datasets - use DDE (Dynamic Data Exchange), especially for Excel. Import wizard can also work here…especially on.csv files - maybe the best way? Read other software’s datasets directly into SAS - one example is a transport file - can also use Import Wizard here…

2 Raw data Data directly in the stream of the SAS program is called “raw”. Use the datalines; or cards; statements. First line of data must immediately follow the datalines; statement. See our first SAS program… Data in an external raw data file. Use the infile statement to point SAS to the location of the file containing the data (i.e., give the path) Do the example program in section 2.4. Look at the Example Code file on the website…

3 Look at Dr. Padgett’s dataset… Use column and/or list input as needed (see section 2.5) to read in the data... print it out and get a plot of total mass against plant height... But first... let’s look at these two types of input in some detail...

4 READING RAW DATA Use INPUT statement - very flexible... –gives variable name, type and position –can read data with different types of separators LIST INPUT - different variables’ values are separated by at least one space - see section 2.5 –must read all data values in the record –no embedded spaces in data values –character data values at most 8 characters –all missing data values indicated by a. (period) –no special formatting of data values

5 Use the example code from the textbook on my website.. use it to save time and to give you examples to work with... e.g., I’ll copy the example program in section 2.5 below: * Create a SAS data set named toads; * Read the data file ToadJump.dat using list input; * DF Modified the program with DATALINES instead of INFILE...; DATA toads; *INFILE 'c:\MyRawData\ToadJump.dat'; INPUT ToadName $ Weight Jump1 Jump2 Jump3; DATALINES; Lucky 2.3 1.9. 3.0 Spot 4.6 2.5 3.1.5 Tubs 7.1.. 3.8 Hop 4.5 3.2 1.9 2.6 Noisy 3.8 1.3 1.8 1.5 Winner 5.7... ; * Print the data to make sure the file was read correctly; PROC PRINT DATA = toads; TITLE 'SAS Data Set Toads'; RUN;

6 Column Input - requires that the data values for different variables be lined up in columns –spaces not required between variable values –missing values can be left blank –character data can have embedded blanks –specific variables can be read and others can be skipped –change the INPUT statement to include the column numbers where the named variables can be found - this requires exact counting of columns in the data listing INPUT VisitingTeam $ 1-20 ConcessionSales 21-24 BleacherSales 25-28 OurHits 29-31 TheirHits 32-34 OurRuns 35-37 TheirRuns 38-40; SEE EXAMPLE CODE ON PAGE 41...USE A “COUNTER” IN THE DATA, AND THEN IGNORE IT IN THE INPUT STATEMENT

7 PROC CONTENTS proc contents data= your dataset name ; gives lots of information about the SAS datasets you have created (either temporary or permanent ones {more later about these}). Try it on the example datasets we’ve been working on...

8 Permanent SAS datasets Permanent SAS datasets are formed in your SAS programs by so naming them in the DATA name_here ; statement... They are saved permanently with all the variable names and formats, etc. that you created when you ran the DATA step... We will show more about these later...

9 Some paths of interest are: – C:\Windows\Desktop\filename (Older Windows) – C:\Documents and Settings\username\Desktop\filename (XP) – A:\filename (floppy disk) – E:\filename (flashdrive)

10 Homework Read sections 2.1-2.6. Use both list and column inputs on the example datasets... Try to save your data as permanent SAS datasets - go back and review section 1.11


Download ppt "Chapter 2 Getting Data into SAS Directly enter data into SAS data sets –use the ViewTable window. You can define columns (variables) with the Column Attributes."

Similar presentations


Ads by Google