1 chapter 2: working with data in a project 2.1 introduction to tabular data 2.2 accessing local...

49
1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files 2.5 Editing Tables in the Data Grid (Self-Study)

Upload: helen-park

Post on 04-Jan-2016

221 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

1

Chapter 2: Working with Data in a Project

2.1 Introduction to Tabular Data

2.2 Accessing Local Data

2.3 Accessing Remote Data

2.4 Importing Text Files

2.5 Editing Tables in the Data Grid (Self-Study)

Page 2: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

2

Chapter 2: Working with Data in a Project

2.1 Introduction to Tabular Data2.1 Introduction to Tabular Data

2.2 Accessing Local Data

2.3 Accessing Remote Data

2.4 Importing Text Files

2.5 Editing Tables in the Data Grid (Self-Study)

Page 3: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

3

Objectives State the definition of a SAS table. State how data is stored in a SAS table.

Page 4: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

4

IntroductionTo begin work with SAS Enterprise Guide, you

1. create a project

2. add data to the project

3. run tasks against the data.

Additionally, you can

4. customize results

5. automate the process.

Page 5: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

5

Microsoft Excel Microsoft Excel spreadsheetsspreadsheets

dBASE filesdBASE files

HTML tablesHTML tablesODBC-ODBC-compliant datacompliant data

OLE DB OLE DB provider’s filesprovider’s files

Microsoft Microsoft AccessAccess tablestables

Fixed-width Fixed-width and delimited and delimited

text filestext files

Common Data FormatsSAS Enterprise Guide can read and use data from a variety of different formats.

SAS tablesSAS tables

Page 6: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

6

SAS Data TablesA SAS data table is a rectangular table of rows and columns.

Columns (variables)

Rows (observations)

Page 7: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

7

SAS Data TablesAll columns must have a name, type, and length.

Names can be1 to 32

characters long.

Page 8: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

8

A column’s type is either character or numeric. The type plays a role in determining the length.

Character values are1 to 32,767 characters

(bytes) long.

Numeric values are 8 bytesof floating point storage: Numeric Currency Date (days from 01JAN1960) Time (seconds from midnight)

SAS Data Tables

Page 9: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

9

SAS Data TablesA format is used to control how values are displayed. Formats do not affect how values are stored.

Format: MMDDYYWidth: 10Stored value: 15060

Format: DOLLARWidth: 10Decimal Places: 0Stored value: 76806

Page 10: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

10

Formats

Page 11: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

11

SAS Data Table Properties

Page 12: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

12

Missing ValuesIf a data value is not present for a column in a particular row, it is considered missing. A missing character value is displayed as a blank. A missing numeric value is displayed as a period or dot.

..

.

Page 13: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

13

Chapter 2: Working with Data in a Project

2.1 Introduction to Tabular Data

2.2 Accessing Local Data2.2 Accessing Local Data

2.3 Accessing Remote Data

2.4 Importing Text Files

2.5 Editing Tables in the Data Grid (Self-Study)

Page 14: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

14

Objectives Add a local Excel spreadsheet to the project. View the properties of the data.

Page 15: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

15

Software File AttributesThe software file

contains metadata.

The software file does not contain

metadata.

Page 16: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

16

Open Options for Data Sources Other than SAS

Enables SAS Enterprise Guide to read data directly

Provides a detailed import process to create

a new SAS table

Page 17: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

17

ScenarioAdd an Excel spreadsheet to the project to provide a list of supplier names and addresses.

Page 18: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

18

This demonstration illustrates how to add a local Excel spreadsheet to the project.

Adding a Local Excel Spreadsheet to the Project

Page 19: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

19

Chapter 2: Working with Data in a Project

2.1 Introduction to Tabular Data

2.2 Accessing Local Data

2.3 Accessing Remote Data2.3 Accessing Remote Data

2.4 Importing Text Files

2.5 Editing Tables in the Data Grid (Self-Study)

Page 20: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

20

Objectives Identify remote data sources. Access a remote server. Add remote data to a project.

Page 21: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

21

Transparent Access to Remote Data

Local User

UNIX

sas

OracleDB2

z/OSMainframe

Oracle

sas

sas WindowsServer

sas

Page 22: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

22

Opening Data from a SAS Server

The Libraries icon enables access to predefined

folders containing SAS or DBMS data sources.

The Files icon enables access to the

directories available on the server.

Page 23: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

23

The Server List window also provides an organized view of all of your files and data sources.

Accessing Remote Data

Server List

Page 24: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

24

After you add a data source to a project, the table automatically opens in the Data Grid.

Accessing Remote Data

Page 25: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

25

Accessing Remote DataTo prevent a table from opening automatically when added to a project, disable the following option by selecting Tools Options.

Page 26: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

26

ScenarioAdd a remote DB2 table to the project. The table contains information on the transactions for products and stores.

Page 27: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

27

This demonstration illustrates how to add a remote data table to the project.

Adding a Remote Tableto a Project

Page 28: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

28

Chapter 2: Working with Data in a Project

2.1 Introduction to Tabular Data

2.2 Accessing Local Data

2.3 Accessing Remote Data

2.4 Importing Text Files2.4 Importing Text Files

2.5 Editing Tables in the Data Grid (Self-Study)

Page 29: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

29

Objectives Use the Import Data task to import a text file

into a project as a SAS table.

Page 30: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

30

Import Data TaskThe Import Data task can be used to convert a file into a customized SAS data table.

Page 31: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

31

Import Data TaskTo your computer, a text file is only strings of characters. SAS Enterprise Guide requires that the data be arranged into rows and columns (observations and variables).

Page 32: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

32

Import Data TaskThe Import Data task enables you to tell SAS Enterprise Guide the following: where each column is located in the text file which columns to read in the name of each column if the first row contains column headings the type of data in each column

– character– numeric (currency, date, time)

how much storage space to allocate how to display the data values

Page 33: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

33

Import Data TaskThe Import Data task stores the data as a SAS table.

Page 34: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

34

ScenarioLLB Importers has a fixed-width text file named Orders.

The file contains orders received this quarter from delicatessens. Create a SAS table named Orders.sas7bdat that has the following characteristics: does not contain the customer order number assigns a descriptive label to the product identification

number displays the selling price and revenue as a currency

Page 35: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

35

ScenarioOrders.txt Orders.sas7bdat

Page 36: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

36

This demonstration illustrates the functionality available when you use the Import Data task to read data.

Adding Data from a Fixed-width Text File

Page 37: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

37

Complete the Chapter 2 exercises starting on page 2-51.

Detailed solutions are provided starting on page 2-52.

Exercises

Page 38: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

38

Chapter 2: Working with Data in a Project

2.1 Introduction to Tabular Data

2.2 Accessing Local Data

2.3 Accessing Remote Data

2.4 Importing Text Files

2.5 Editing Tables in the Data Grid (Self-Study)2.5 Editing Tables in the Data Grid (Self-Study)

Page 39: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

39

Objectives Use the Data Grid to delete columns and rows. Use the Data Grid to modify column attributes

and sort a table. Use the Expression Builder to create columns.

Page 40: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

40

Data GridWhen you add a table to a project, the Data Grid’s default behavior is to display the table automatically in read-only mode.

Actions available in the Data Grid in read-only mode include the following: browsing SAS tables and other tables resizing row and column widths for better viewing copying rows and columns to paste into a new or

existing SAS table hiding rows and columns from view holding rows and columns while scrolling

Page 41: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

41

Data GridActions available in the Data Grid in update mode are limited to SAS tables and include all actions available in read-only mode, as well as the ability to do the following: edit data values change the names of columns apply labels and formats to columns delete rows and columns sort by multiple columns in ascending or descending

order create new columns and add rows

When you modify a table through the Data Grid,you change the actual data values in the table.

When you modify a table through the Data Grid,you change the actual data values in the table.

Page 42: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

42

Data Grid: Creating a Column

Page 43: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

43

Column Properties: General Tab

Type a name upto 32 characters

in length.

Type theexpression…

…or use theExpression

Builder.

Set thecolumn type.

Page 44: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

44

Expression Builder: Creating a ColumnOne use of the Expression Builder is to insert a new column into a data table that is computed from other columns or values.

Page 45: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

45

Expression Builder: Function Tab

Read a description of the function.

Selectthe type

of function. Selecta specificfunction.

Page 46: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

46

Expression Builder: Values Tab

Select thecolumn nameto include it

in the expression.

Click on the table to view its column

names.

Page 47: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

47

Data Grid: Results

Page 48: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

48

ScenarioLLB’s UPDATEORDERS table must be updated. Delete the UnitsInStock column because the

information is no longer needed. Delete order #0713 because the order was cancelled. Create a new column called Revenue that is

computed as Quantity * SellPrice.

Page 49: 1 Chapter 2: Working with Data in a Project 2.1 Introduction to Tabular Data 2.2 Accessing Local Data 2.3 Accessing Remote Data 2.4 Importing Text Files

49

This demonstration illustrates how to switch from Read-only mode to Update mode in the Data Grid in order to modify a SAS table.

Working with Tablesin the Data Grid