1 Chapter 2: Working with Data in a Project 2.1 Understanding SAS Data Structure 2.2 Importing Data...

Preview:

Citation preview

1

Chapter 2: Working with Data in a Project

2.1 Understanding SAS Data Structure

2.2 Importing Data Files Other Than SAS Files

2.3 Accessing Data via SAS Libraries

2

Chapter 2: Working with Data in a Project

2.1 Understanding SAS Data Structure2.1 Understanding SAS Data Structure

2.2 Importing Data Files Other Than SAS Files

2.3 Accessing Data via SAS Libraries

3

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

4

Common Data FormatsSAS Enterprise Guide can read and use data from a variety of different formats including the following: SAS data sets Microsoft Excel and Access DBMS tables Text files JMP HTML SPSS

5

6

2.01 Multiple Answer PollWhich types of data do you work with?

a. Microsoft Excel

b. Microsoft Access

c. DBMS tables (such as Oracle or DB2)

d. SAS data sets

e. Text files (delimited files)

f. Other

7

SAS Data SetA SAS data set (or table) is a rectangular table of rows and columns.

Rows(observations

)

Columns (variables)

8

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

It is recommended that column names also start with a letter or underscore include only letters, underscores, and numbers.

Names can be 1 to 32 characters long.

9

SAS Data SetA column’s type is either character (string) or numeric. The type plays a role in determining the length.

Charactervalues are1 to 32,767characters

(bytes) long.

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

10

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

Format: DATEWidth: 9Stored value: 16497

Format: DOLLARWidth: 10Decimal Places: 2Stored value: 234.60

11

Formats

12

13

2.02 Multiple Choice PollWhich of the following variable attributes is not required?

a. Name

b. Type

c. Length

d. Format

14

2.02 Multiple Choice Poll – Correct AnswerWhich of the following variable attributes is not required?

a. Name

b. Type

c. Length

d. Format

15

SAS Data Set PropertiesViewing a data set’s properties enables you to examine the data set and column attributes.

16

17

2.03 Multiple Choice PollOpen the employee_organization data set. Click the Properties button on the toolbar and select Columns.

What is the length of the variable Job_Title?

a. 8

b. 9

c. 25

d. 40

18

2.03 Multiple Choice Poll – Correct AnswerOpen the employee_organization data set. Click the Properties button on the toolbar and select Columns.

What is the length of the variable Job_Title?

a. 8

b. 9

c. 25

d. 40

19

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.

.

20

Chapter 2: Working with Data in a Project

2.1 Understanding SAS Data Structure

2.2 Importing Data Files Other Than SAS Files2.2 Importing Data Files Other Than SAS Files

2.3 Accessing Data via SAS Libraries

21

Objectives Import a Microsoft Excel spreadsheet and create

a SAS data set. Import a fixed-width text file and create

a SAS data set. View the properties of the data.

22

Business Scenario Orion maintains a Microsoft Excel file named products and a fixed-width text file named orders. To use these data sources in SAS Enterprise Guide, they must be imported into SAS data sets.

23

Adding Data to a ProjectWhen a SAS data set is added to a project, SAS Enterprise Guide is able to read and open the data immediately. A shortcut to the data is added to the project.

24

25

2.04 QuizSelect File Open Data… and navigate to the location of the course data if necessary.

What happens when you open the products Excel file?

26

2.04 Quiz – Correct AnswerSelect File Open Data… and navigate to the location of the course data if necessary.

What happens when you open the products Excel file?

The Import Data task automatically opens.

27

Importing Data Not in a SAS Data SetThe Import Data wizard can be used to read text, HTML, or PC-based data files (including Microsoft Excel and Microsoft Access) and to create SAS data sets.

28

Step 1: Specify DataThe first step is to confirm the source data and designate the output SAS data set name and storage location.

Verify the fileto be imported.

Change the name andstorage location for theoutput SAS data set.

29

Step 2: Select Data SourceWhen you read from structured data such as Microsoft Excel or Access, choose the data to be read and indicate whether the first row contains field names.

30

Step 2: Select Data SourceWhen you read from non-structured data such as a text file, choose the text format and indicate how the columns should be split.

31

32

2.05 Multiple Answer PollIf the Rename columns to comply with SAS naming conventions. option is selected, which column headings would be modified in the imported data set?

a. Product_Category

b. Product Name

c. Discount%

d. Supplier-Country

33

2.05 Multiple Answer Poll – Correct AnswersIf the Rename columns to comply with SAS naming conventions. option is selected, which column headings would be modified in the imported data set?

a. Product_Category

b. Product Name

c. Discount%

d. Supplier-Country

Spaces and special symbols are replaced with an underscore.

34

Step 3: Define Field Attributes Set column attributes for columns included in the imported SAS data set.

35

Step 4: Advanced OptionsSelect any applicable advanced options.

36

Import Data ResultsThe new SAS data set is created and accessible via the Project Tree or Process Flow window.

37

Updating ResultsThe Import Data wizard can be rerun or modified from the Output Data tab.

Use the buttonto refresh theoutput data set.

Use Modify Task to reopenthe Import Data wizardand make changes.

38

Using the Import Data Task

This demonstration illustrates how import a Microsoft Excel and fixed-width text file to create SAS data sets.

39

40

Setup for the Quiz (Live Web Only)Import the Products Excel file and create a SAS data set:

1.Create a new project.

2.Add the Products Excel file. (Select File Open Data….)

3.In step 1, verify that the output SAS data set is Products.

4.In step 2, verify that the ProductList worksheet is highlighted and that First row of range contains field names is selected.

5.Accept the default settings in step 3 and 4.

6.Select Finish to create the new SAS data set.

41

2.06 QuizWhat do you select to make a change in the Import Data task, such as change the name of the first variable?

42

2.06 Quiz – Correct AnswerWhat do you select to make a change in the Import Data task, such as change the name of the first variable?

Modify Task

43

Using the Import Data Task (continued)

This demonstration illustrates how import a Microsoft Excel and fixed-width text file to create SAS data sets.

44

45

Exercise

This exercise reinforces the concepts discussed previously.

46

47

Chapter 2: Working with Data in a Project

2.1 Understanding SAS Data Structure

2.2 Importing Data Files Other Than SAS Files

2.3 Accessing Data via SAS Libraries2.3 Accessing Data via SAS Libraries

48

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

49

Business ScenarioOrion Star wants to use SAS Enterprise Guide to access a DBMS table on a remote server. The table includes information about customer orders.

50

Transparent Access to Remote Data

UNIX

Local User

z/OSMainframe

WindowsServer

51

SAS LibrariesA SAS library is a collection of files that are defined, recognized, and accessible by SAS. Libraries can be used to access SAS or DBMS data.

Example: The ORION library can be defined to reference all SAS data sets in s:\workshop.

52

Opening Files from a SAS Server or FolderThe Open Data dialog box enables you to access files from servers where SAS is installed and configured to run with SAS Enterprise Guide.

The Libraries iconenables access topredefined folderscontaining SAS orDBMS data sources.

The Files icon enables access to the directories available on the server.

53

Accessing Data via SAS ServersThe Resources pane provides another method to view and access all of your available files and data sources.

SAS Folders areused in the platformfor SAS BusinessAnalytics.

54

55

2.07 Quiz1. Select View Server List or click the Server List

icon in the Resources pane below the Project Tree.

2. Expand Servers your server name Libraries.

What libraries are listed?

56

2.07 Quiz – Correct Answer1. Select View Server List or click the Server List

icon in the Resources pane below the Project Tree.

2. Expand Servers your server name Libraries.

What libraries are listed?

Possible answers:

Work , Sashelp, Sasuser, EGTASK, MAPS

57

2.08 QuizIn the Server List window, expand the Files icon.

What is listed?

58

2.08 Quiz – Correct AnswerIn the Server List window, expand the Files icon.

What is listed?

The file structure of the server

59

Defining SAS LibrariesSAS libraries are typically set up by your SAS administrator. However, the Assign Project Library wizard can be used to define libraries to SAS or DBMS data sources for which you have Read permission.

60

Accessing Remote DataAfter you add a data source to a project, by default it automatically opens in the data grid.

61

Adding a Data Set via a SAS Library

This demonstration illustrates how to define a project library and add a data set to the project via the library definition.

62

63

64

Setup for the Poll1. Use the Assign Project Library task to create the

ORION library and point to the location of the course data. (Select Tools Assign Project Library….)

2. Include the ACCESS=READONLY option in step 3 of the task.

3. View the ORION library in the Server List. If you do not see the library or the data sets, right-click Servers and select Refresh.

4. Right-click on the travel_expenses table in the Server List and select Copy.

5. Right-click on the Work library and select Paste.

6. Double-click the travel_expenses table in the Work library to add it to the project.

65

2.09 PollRight-click travel_expenses in the Process Flow or Project Tree window and select Delete.

Is the table deleted from the library?

Yes

No

66

2.09 Poll – Correct AnswerRight-click travel_expenses in the Process Flow or Project Tree window and select Delete.

Is the table deleted from the library?

Yes

No

Only the shortcut isremoved from the project,but the table remains in the library.

67

2.10 PollRight-click travel_expenses under the Work library in the Server List and select Delete.

Are you able to delete the table?

Yes

No

68

2.10 Poll – Correct AnswerRight-click travel_expenses under the Work library in the Server List and select Delete.

Are you able to delete the table?

Yes

No

If you have Write access to a library and the data sets within, you can move, copy, and delete files in the Server List.

These actions cannot be undone, so be careful!

69

2.11 PollRight-click travel_expenses under the ORION library in the Server List and select Delete.

Are you able to delete the table?

Yes

No

70

2.11 Poll – Correct AnswerRight-click travel_expenses under the ORION library in the Server List and select Delete.

Are you able to delete the table?

Yes

No

Because you used the ACCESS=READONLY option when you defined the ORION library, you cannot make changes to the contents.

71

72

Chapter Review1. What are the two types of columns in a SAS data set?

What happens to a date? How is it stored?

 

2. What SAS item is used to control the way that a data value is displayed in a report?

73

Chapter Review Answers1. What are the two types of columns in a SAS data set?

What happens to a date? How is it stored?

 

2. What SAS item is used to control the way that a data value is displayed in a report?

The two types are character and numeric. A date is stored as an integer representing the number of days between January 1, 1960 and a specific date.

A SAS format is used to control how a data value is displayed. For example, the DOLLARw.d format displays a numeric value with dollar signs, commas, and the specified number of decimals.

74

Chapter Review3. True or False: When you access data via the

Import Data task, a new SAS data set is created.

4. True or False: When you add a data source to a project by selecting File Open Data, the data is saved in the project.

5. What type of files can you import with the Import Data task?

75

Chapter Review Answers3. True or False: When you access data via the

Import Data task, a new SAS data set is created.

True 

4. True or False: When you add a data source to a project by selecting File Open Data, the data is saved in the project.

5. What type of files can you import with the Import Data task?

False: A pointer to the data source is saved in the project.

You can import Microsoft Excel and Access data as well as text files.

Recommended