Beruflich Dokumente
Kultur Dokumente
Bobby Kidd
Vice President
Senior Statistical Portfolio Analyst
First Horizon National Corp
The Basics
Very similar to working with flat files
Starts with filename statement
DDE
triplet: program|
filepath[filename]sheet!location
Filename sample DDE excel|c:\foo\
[bar.xls]yourdatahere!R4c5;
Mild
filename readme dde 'excel|C:\...\SAS Pres\
[samples.xls]Read Me!R5C3:R14C6';
data DDERead;
infile readme;
informat Name $8. Sex $1. Purchase_Amount
dollar8.2 State$2.;
input Name$ Sex$ Purchase_Amount State$;
run;
Read Data
Be mindful of informats
Mild
Mild
filename writeme1 dde 'excel|C:\...\SAS Pres\
[samples.xls]Write Me!R5C2:R8C3';
filename writeme2 dde 'excel|C:\...\SAS Pres\
[samples.xls]Write Me!R12C2:R13C3';
data _null_;
set state;
file writeme1;
put State Total;
run;
data _null_;
set sex;
file writeme2;
put Sex Total;
run;
Write Data
Medium
filename readme dde 'excel|C:\...\SAS
Pres\[samples.xls]Read Me!
R5C3:R14C6' notab;
data readdde;
infile readme dlm = '09'x;
informat Name $8. Sex $1.
Purchase_Amount dollar8.2 State$2.;
input Name Sex Purchase_Amount
State;
run;
Increase Control
Medium
Without dlm=09x and notab
Medium
filename MinP dde 'excel|C:\...\SAS Pres\
[samples.xls]Write Me!R16C2:R16C3'
notab;
filename MaxP dde 'excel|C:\...\SAS Pres\
[samples.xls]Write Me!R19C2:R19C3'
notab;
data _null_;
set min;
file MinP;
Put Name '09'x Purchase_Amount;
run;
data _null_;
set max;
file MaxP;
Put Name '09'x Purchase_Amount;
run;
Medium
Without notab, with 09x: spaces become tabs
Hot
Beyond Data: Formatting, formulas, files
Its
Available
from Microsoft
Macro4 helpfile
Contains most if not all Excel macro4 functions
Filename
Allows
Macro Functions
Hot
Example Format.font
Hot
Excel must be opened first
Manual
Easy
but tedious
command
Issues
DOS commands
Noxwait, noxsync allow SAS to run
concurrently with Excel
Doesnt like spaces
Use cd to reach folders with spaces in names
Hot
Start Excel
Options noxwait noxsync;
x 'cd c:\Program files\microsoft office';
x 'Office10\excel.exe';
Open file
Use sleep function to ensure excel has loaded
before issuing commands.
Commands still issued with put statements
Hot
Implementation
filename cmds dde 'excel|system';
data _null_;
file cmds;
put '[select("r5c2:r8c2")]';
put '[format.font(times new roman",,1)]';
run;
data _null_;
file cmds;
put [select(r5c3:r8c3)];
put [format.number($#,###.00)];
run;
Hot
Save, close and Quit
Save.as()
to save file
File-close() to close the wookbook
Quit() to end excel
Commands still issued with put statements
data
_null_;
file cmds;
put '[save.as("C:\...\Sas Pres\sample.xls")]';
put '[file-close()]';
put '[quit()]';
run;
put [formula("=sum(R[-19]C:R[-14]C)/R38C20")];
put [formula("=sum(R12C20:R17C20)/R38C20")];
put "[formula(""=sum(R[-19]C:R[-14]C)/R38C&col."")]";
Complete Automation
Read, Write and Manipulate Excel all
from within SAS
With use of SAS wakeup function can
schedule reports to be ready when you
show up to work
Hit F8 and walk away
Questions