A Comparison of SAS versus Microsoft Excel and Access’s Inbuilt VBA Functionality

advertisement
A Comparison of SAS versus Microsoft
Excel and Access’s Inbuilt VBA
Functionality
Jozef Tarrant, Amadeus Software Ltd.
Copyright © 2011 Amadeus Software Ltd.
1
Overview
 What is VBA?
 VBA Essentials: Modules and Subroutines
 Programming an Export from Excel to CSV
 Programming an Import from CSV to Access
 Comparison of VBA versus SAS
Copyright © 2011 Amadeus Software Ltd.
2
What is VBA?
 VBA (Visual Basic for Applications) is an event-driven
programming language built into most Microsoft Office
applications, often informally referred to as ‘Macro’.
 It allows us to script and automate almost any procedure
that can be done manually.
 It lends itself to any procedure that the user finds
themselves having to do repetitively.
 Or to any task that an administrator would prefer to be
automatic and not subject to user input and associated
error.
Copyright © 2011 Amadeus Software Ltd.
3
VBA is entered inside code modules
Copyright © 2011 Amadeus Software Ltd.
4
The Principle
Multiple Excel worksheets and
workbooks
Copyright © 2011 Amadeus Software Ltd.
Single Access database
read and consolidated into
5
The Practice
consolidated
into
Multiple Excel worksheets and
workbooks
Copyright © 2011 Amadeus Software Ltd.
exported
to
Single Excel
worksheet
Access database
6
Example of source spreadsheets
Copyright © 2011 Amadeus Software Ltd.
7
Demonstration of Process
Copyright © 2011 Amadeus Software Ltd.
8
Defining Variables with DIM Statements
Dim
Dim
Dim
Dim
Dim
Dim
Dim
Dim
Dim
Dim
Dim
Name
anyname1
anyname2
anyname3
anyname4
anyname5
anyname6
anyname7
anyname8
anyname9
anyname10
anyname11
Copyright © 2011 Amadeus Software Ltd.
anyname1 as Integer
anyname2 as String
anyname3 as Worksheet
anyname4 as Database
anyname5 as TableDef
anyname6 as Boolean
anyname7 as Object
anyname8 as DAO.Database
anyname9 as DAO.Recordset
anyname10 as DAO.Field
anyname11
Type
Numeric variable
Character variable or string
Excel worksheet
ODBC database
Table view or editing interface
Boolean variable
Any other object
DAO (Data Access Object) enabled
database
DAO (Data Access Object) enabled
recordset
DAO (Data Access Object) enabled field
Call to application, no type needs to be
specified
9
Code Module 1 Highlights
Copyright © 2011 Amadeus Software Ltd.
10
Code Module 1 Highlights
Copyright © 2011 Amadeus Software Ltd.
11
Code Module 1 Highlights
Copyright © 2011 Amadeus Software Ltd.
12
Code Module 2 Highlights
Copyright © 2011 Amadeus Software Ltd.
13
Code Module 2 Highlights
Copyright © 2011 Amadeus Software Ltd.
14
Code Module 2 Highlights
Copyright © 2011 Amadeus Software Ltd.
15
... The halfway stage
Copyright © 2011 Amadeus Software Ltd.
16
Creating tables in Access
 Data view
 Design view
Copyright © 2011 Amadeus Software Ltd.
17
Creating forms and associating actions
Copyright © 2011 Amadeus Software Ltd.
18
Dialogue boxes in action
Copyright © 2011 Amadeus Software Ltd.
19
Target table is updated
Copyright © 2011 Amadeus Software Ltd.
20
VBA vs. SAS
VBA
SAS
Consolidation through importing to
Excel
Consolidation through PROC IMPORT or
CONNECT TO ODBC
IF statements control reading
IF and WHERE statements control
reading and writing
Exporting to Access by creating
temporary recordset object
Write out directly to an external
database
Copyright © 2011 Amadeus Software Ltd.
21
VBA vs. SAS continued
VBA
SAS
Explicit loops
Implied loops
Variables have to be defined in type and
number
Allows the user to create variables as
and when needed
Requires interfaces with external objects SAS uses built-in, or sometimes
to be explicitly programmed and
additionally licensed, engines to
embedded
interface with external objects
Custom functions
Copyright © 2011 Amadeus Software Ltd.
Parameterized macros
22
Conclusions
 Both VBA and SAS are perfectly good options to
consolidate data from multiple sources
 VBA is included as part of MS Office, although no formal
support is provided
 SAS is much easier to use and benefits from greater
discipline across all procedures and functions
Copyright © 2011 Amadeus Software Ltd.
23
 ... Any Questions?
Jozef Tarrant
Amadeus Software Ltd.
Tel: +44 (0)1993 848010
e-Mail: jozef.tarrant@amadeus.co.uk
Web: www.amadeus.co.uk
Copyright © 2011 Amadeus Software Ltd.
24
Download