Transcript Slide 1

Chapter 1: Introduction
1.1 Course Logistics
1.2 Course Overview
1
Chapter 1: Introduction
1.1 Course Logistics
1.2 Course Overview
2
Objectives



3
Explain the naming convention that is used for the
course files.
Describe at a high level how data is used and stored
at Orion Star Sports & Outdoors.
Navigate to the Help facility.
Filename Conventions
m204d01x
course ID
Code
4
Type
a
Activity
d
Demo
e
Exercise
s
Solution
chapter #
type
m204a01
m204a02
m204a02s
m204d01
m204d02
m204e01
m204e02
m204s01
m204s02
item #
placeholder
Example:
The SAS Macro
Language 2
course ID is m2, so
m204d01 =
SAS Macro Language 2,
Chapter 4, Demo 1.
Orion Star Sports & Outdoors
Orion Star Sports & Outdoors is a fictitious global sports
and outdoors retailer with traditional stores, an online
store, and a large catalog business.
The corporate headquarters is located in the United
States with offices and stores in many countries
throughout the world.
Orion Star has about 1,000 employees and 90,000
customers, processes approximately 150,000 orders
annually, and purchases products from 64 suppliers.
5
Orion Star Data
As is the case with most organizations, Orion Star has
a large amount of data about its customers, suppliers,
products, and employees. Much of this information is
stored in transactional systems in various formats.
Using applications and processes such as SAS Data
Integration Studio, this transactional information was
extracted, transformed, and loaded into a data
warehouse.
Data marts were created to meet the needs of specific
departments such as Marketing.
6
The SAS Help Facility
7
Creating Favorites
in the SAS Help Facility
This demonstration illustrates how to add
a favorite under the Favorites tab in the
SAS Help facility.
8
Chapter 1: Introduction
1.1 Course Logistics
1.2 Course Overview
9
Objectives

10
Describe the tasks in the course.
Business Scenario
The application developers at Orion Star Sports &
Outdoors need to implement an improved and
streamlined development environment.
Currently they have programs and macros that have
these problems:
 require a high level of maintenance to utilize
different data
 require customization for reuse of existing code
 fail to execute due to invalid parameter values
 do not support input parameters and data values
with special characters
11
Implementing Development Guidelines
The first step for the programmers is to implement a set
of guidelines for developing macro applications. They
want applications to meet the following qualifications:
 supporting best practices for developing macro
applications
 implementing debugging tools
 performing parameter validation
 creating efficient macros
 utilizing local symbol tables
 incorporating application portability
12
Utilizing Macro Programming Techniques
The following examples illustrate areas that Orion Star's
programmers can address by utilizing macro
programming techniques.
Areas addressed in this course include the following:
 reading and processing data
 creating reusable macros
 working with macro parameters
13
Reading and Processing Data
Currently, the Orion programmers have many programs
that create and refresh data sets based on both of these
types of files:
 existing SAS data sets
 external files
To reduce the number of redundant programs, they want
to modify some of the macros to accept a libref or a
directory name versus a data set name.
14
Reading and Processing Data
They want a single macro to archive all data sets in a
given library.
No_rows
Orders03
Order_fact
Prodlist
Products
%RENAME
No_rows_NOV2008
15
Order_fact_NOV2008
Orders03_NOV2008
Products_NOV2008
Prodlist_NOV2008
Reading and Processing Data
They want a single macro to import all Excel files found in
a given directory.
custfm.xls
customertype.xls
Sales.xls
OrderFact.xls
daily_sales.xls
%IMPRTXLS
custfm
16
customertype
Sales
OrderFact
daily_sales
Creating Reusable Macros
The Orion Star programmers want to create utility macros
for repetitive tasks and share them with other
programmers and applications.
Examples of repetitive tasks include the following:
 converting all parameter values to uppercase
 checking the existence of a data set
 extracting data set attributes
17
Creating Reusable Macros
The UPVALUE macro is called in several macros to
convert parameter values to uppercase.
%CUSTOMERS(us)
%SALESREP(Elvish, Irenie)
%CLUBLIST(gd)
%UPVALUE
Sales Report for ELVISH, IRENIE
Customers from US
Obs
1
2
4
6
9
10
18
Customer_Name
James Kvarniq
Sandrina Stephano
Karen Ballinger
David Black
Jimmie Evans
Tonie Asmussen
Customer_A
4382 Graly
6468 Cog H
425 Bryant
1068 Haith
391 G
Employee_ID
Order_
Date
120121
120121
120121
120121
24JUN2004
25NOV2004
12JAN2005
12MAR2006
Total_Retail_
Price
$10.10
$200.10
$16.00
List of Club_Code=GD
Obs
2
3
7
11
Customer_
ID
5
9
13
19
First_Name
Last_Name
Sandrina
Cornelia
Markus
Oliver S.
Stephano
Krahl
Sepke
Working with Macro Parameters
The Orion Star programmers want to improve parameter
validation. Macros need to test parameters and generate
custom error messages.
%MACRO CLUBLIST(LEVEL)
&LEVEL=
ERROR: A null value for LEVEL is not
valid.
The macro will terminate.
Yes
No
&LEVEL=GD or
&LEVEL=IN or
&LEVEL=OR
No
Yes
19
Execute PROC PRINT
ERROR: Value of LEVEL: xxxx is not valid.
The macro will terminate.
Working with Macro Parameters
Because Orion Star receives data from many different
sources, resulting data might contain special characters
such as a comma. Macros must be modified to treat
special characters as text.
56
%macro salesrep(name);
57
proc print data=orion.salesstaff noobs;
58
var Employee_ID Job_Title Salary;
The comma is
59
where Employee_name="&name";
60
title "Salary Information for &name"; misinterpreted
61
run;
as a separator
62
title;
instead of part
63
%mend salesrep;
64
of the value.
65
%salesrep(Shannan, Sian)
ERROR: More positional parameters found than defined.
20