Top Banner
Don’t Import It! Setting Up a SAS Libname to an Excel Spreadsheet or Access Database… in 10 Seconds or Less! Kevin Druhan Wait Time Improvement Office Nova Scotia Department of Health [email protected]
6

Don’t Import It! Setting Up a SAS Libname to an Excel Spreadsheet or Access Database… in 10 Seconds or Less! Kevin Druhan Wait Time Improvement Office.

Dec 28, 2015

Download

Documents

Olivia Davis
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Don’t Import It! Setting Up a SAS Libname to an Excel Spreadsheet or Access Database… in 10 Seconds or Less! Kevin Druhan Wait Time Improvement Office.

Don’t Import It!

Setting Up a SAS Libname to an Excel Spreadsheet or Access Database…in 10 Seconds or Less!

Kevin DruhanWait Time Improvement OfficeNova Scotia Department of [email protected]

Page 2: Don’t Import It! Setting Up a SAS Libname to an Excel Spreadsheet or Access Database… in 10 Seconds or Less! Kevin Druhan Wait Time Improvement Office.

To Import or Not to Import • Usually preferable to have your data in (SAS7BDAT) format

– Stores SAS formats and metadata permanently– Rapid I/O (no translation required when querying data)

• REALITY CHECK– The #1 Business Intelligence tool in the world is…Microsoft EXCEL.– The #1 DBMS in the world is…Microsoft Access.– You will almost certainly be analyzing EXCEL/ACCESS data at some

point in your SAS career!

• When your source data changes frequently, you should consider linking directly to it in SAS– Otherwise you will be forced to constantly re-import into SAS datasets!– Eg. Real-time reporting on a production database (dashboards etc)

You can use Excel sheets/Access tables in SAS seamlessly as if they were SAS datasets by setting up a SAS libname that points to the spreadsheet / database!

You can use Excel sheets/Access tables in SAS seamlessly as if they were SAS datasets by setting up a SAS libname that points to the spreadsheet / database!

Page 3: Don’t Import It! Setting Up a SAS Libname to an Excel Spreadsheet or Access Database… in 10 Seconds or Less! Kevin Druhan Wait Time Improvement Office.

Excel - How to do it1. Click on Libraries in the Explorer pane.

2. Right-click over any white space and select New to create a new library.

3. Under Name, type the libname you want to give your library (8 characters max!)

4. Under Engine, select EXCEL.

5. Under Workbook, click on Browse and select your Excel file.

6. Under Version, select the version of Excel workbook (usually 2002)

7. Under Header Row, select YES if the field names are on the first line of your Excel workbook (cells A1, B1, C1, etc).

8. Leave Options blank.

9. Check Enable at Startup if you want the library to be set up every time you load up SAS (otherwise you will have to repeat all of these steps every time!)

Page 4: Don’t Import It! Setting Up a SAS Libname to an Excel Spreadsheet or Access Database… in 10 Seconds or Less! Kevin Druhan Wait Time Improvement Office.

Access - How to do it1. Click on Libraries in the Explorer pane.

2. Right-click over any white space and select New to create a new library.

3. Under Name, type the libname you want to give your library (8 characters max!)

4. Under Engine, select ACCESS.

5. Under Database, click on Browse and select your Access database file.

6. Under DB Password, type the database password (if necessary)

7. Leave all other fields blank.

8. Check Enable at Startup if you want the library to be set up every time you load up SAS (otherwise you will have to repeat all of these steps every time!)

Page 5: Don’t Import It! Setting Up a SAS Libname to an Excel Spreadsheet or Access Database… in 10 Seconds or Less! Kevin Druhan Wait Time Improvement Office.

How to Use the Libnames in SAS

• Excel– Use the libname you

set up and the sheet name in the Excel file

– Excel spreadsheets by default contain three sheets: Sheet1, Sheet2, Sheet3.

• Access– Use the libname

you set up and then just use the table names as if they were SAS datasets!

Note the quotation marks, $, and the n.

Page 6: Don’t Import It! Setting Up a SAS Libname to an Excel Spreadsheet or Access Database… in 10 Seconds or Less! Kevin Druhan Wait Time Improvement Office.

Additional Resources

• For more information, read the following SAS Global Forum / Technical papers:

De-Mystifying the SAS® LIBNAME Engine in Microsoft Excel: A Practical Guide

http://www2.sas.com/proceedings/sugi31/024-31.pdf

De-Mystifying the SAS® LIBNAME Engine in Microsoft Excel: A Practical Guide

http://www2.sas.com/proceedings/sugi31/024-31.pdf

Importing Microsoft Access tables to SAS Datasetshttp://archive.chesapeakebay.net/cims/importing_data.pdf

Importing Microsoft Access tables to SAS Datasetshttp://archive.chesapeakebay.net/cims/importing_data.pdf