22
Working Smarter, Not Harder with DDE: Did I Really Spend All That Time Just Formatting My Report? Bobby Kidd Vice President Senior Statistical Portfolio Analyst First Horizon National Corp

Working Smarter, Not Harder with DDE: Did I Really Spend All That Time Just Formatting My Report?

  • Upload
    daryl

  • View
    65

  • Download
    0

Embed Size (px)

DESCRIPTION

Working Smarter, Not Harder with DDE: Did I Really Spend All That Time Just Formatting My Report?. Bobby Kidd Vice President Senior Statistical Portfolio Analyst First Horizon National Corp. Hey, What ’ s With the Acronyms!. DDE stands for Dynamic Data Exchange - PowerPoint PPT Presentation

Citation preview

Page 1: Working Smarter, Not Harder with DDE: Did I Really Spend All That Time Just Formatting My Report?

Working Smarter, Not Harder with DDE:

Did I Really Spend All That Time Just Formatting My Report?

Bobby Kidd

Vice President

Senior Statistical Portfolio Analyst

First Horizon National Corp

Page 2: Working Smarter, Not Harder with DDE: Did I Really Spend All That Time Just Formatting My Report?

Hey, What’s With the Acronyms!

DDE stands for Dynamic Data ExchangeDDE in SAS gives you the ability to read from, write to, and issue program commands to many Microsoft Applications such as Excel and WordSince most reporting is done with Excel we will limit ourselves to that program

Page 3: Working Smarter, Not Harder with DDE: Did I Really Spend All That Time Just Formatting My Report?

But I Can Already Read From and Write To Excel

Proc Import and Proc Export both require the data to start at the top right corner, Cell A1 of the first sheet.DDE, however, can read from and write to any cell or group of cells in any sheet in the file.It can also create new rows, columns, and worksheets.

Page 4: Working Smarter, Not Harder with DDE: Did I Really Spend All That Time Just Formatting My Report?

But, that’s not all!

In addition to the freedom of defining where you want the dataYou can change the format and the fontCopy and Paste from other cells,

worksheets and even other files.Create new new formulasAdd Worksheets, Columns and Rows In short, just about everything you can do

in Excel, you can program into DDE

Page 5: Working Smarter, Not Harder with DDE: Did I Really Spend All That Time Just Formatting My Report?

OK, But why would I want to?

The less man(ual) handling of the data, the better Don’t have to worry about copying over data Don’t have to remember to format those 1 or 2

cells down in the corner of the sheet. How many times have you had to go back and fix

typo’s and formatting errors

Data provided from someone else's formatted reports

Do you really enjoy copying, pasting and formatting the same report every day, week, month when you can make SAS do it all for you in seconds.

Page 6: Working Smarter, Not Harder with DDE: Did I Really Spend All That Time Just Formatting My Report?

The Basics

Very similar to working with flat filesStarts with filename statementDDE triplet: program|

filepath[filename]sheet!locationFilename sample DDE ‘excel|c:\foo\

[bar.xls]yourdatahere!R4c5’;

Read data with input statementWrite data with put statement

Page 7: Working Smarter, Not Harder with DDE: Did I Really Spend All That Time Just Formatting My Report?

Mild

Read Data Be mindful of informats

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;

Page 8: Working Smarter, Not Harder with DDE: Did I Really Spend All That Time Just Formatting My Report?

Mild

Page 9: Working Smarter, Not Harder with DDE: Did I Really Spend All That Time Just Formatting My Report?

Mild

Write Data Just like writing to flat file

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;

Page 10: Working Smarter, Not Harder with DDE: Did I Really Spend All That Time Just Formatting My Report?

Medium

Increase Control Use notab to gain control over delimiters When reading use dlm=’09’x for the tab key Flat file default is space delimited so “Abel C” would be two fields

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;

Page 11: Working Smarter, Not Harder with DDE: Did I Really Spend All That Time Just Formatting My Report?

MediumWithout dlm=’09’x and notab

With dlm=’09’x and notab

Page 12: Working Smarter, Not Harder with DDE: Did I Really Spend All That Time Just Formatting My Report?

Medium

Control Write delimiters Use notab to prevent SAS from changing spaces into tabs Use ’09’x to place tab delimiters where you want them.

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;

Page 13: Working Smarter, Not Harder with DDE: Did I Really Spend All That Time Just Formatting My Report?

MediumWithout notab, with ’09’x: spaces become tabs

With notab, without ’09’x: everything is one field

Page 14: Working Smarter, Not Harder with DDE: Did I Really Spend All That Time Just Formatting My Report?

Hot

Beyond Data: Formatting, formulas, files It’s not a virus: Macrofun.exe

Available from MicrosoftMacro4 helpfileContains most if not all Excel macro4 functions

Filename cmds dde 'excel|system';Allows SAS to issue system commandsOpen, save, and close files, etc.

Page 15: Working Smarter, Not Harder with DDE: Did I Really Spend All That Time Just Formatting My Report?

HotMacro Functions Example Format.font

Function Name and syntax given in detail. Parameter descriptions and values are documented Only need to specify parameters as far as you need Use with Put statement: put '[format.font("script",,1)]';

Page 16: Working Smarter, Not Harder with DDE: Did I Really Spend All That Time Just Formatting My Report?

Hot

Excel must be opened firstManual

Easy but tediousX command

Issues DOS commandsNoxwait, noxsync allow SAS to run

concurrently with ExcelDoesn’t like spacesUse “cd” to reach folders with spaces in names

Page 17: Working Smarter, Not Harder with DDE: Did I Really Spend All That Time Just Formatting My Report?

HotStart 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

filename cmds dde 'excel|system'; data _null_;

file cmds; put '[file-open("C:\...\SAS Pres\sample.xls")]'; run;

Page 18: Working Smarter, Not Harder with DDE: Did I Really Spend All That Time Just Formatting My Report?

Hot

Implementationfilename cmds dde 'excel|system';data _null_; data _null_;file cmds; file cmds;put '[select("r5c2:r8c2")]'; put ‘[select(“r5c3:r8c3”)]’;put '[format.font(“times new roman",,1)]'; put ‘[format.number(“$#,###.00”)];run; run;

Page 19: Working Smarter, Not Harder with DDE: Did I Really Spend All That Time Just Formatting My Report?

HotSave, close and QuitSave.as() to save fileFile-close() to close the wookbookQuit() to end excelCommands still issued with put statements

data _null_;file cmds; put '[save.as("C:\...\Sas Pres\sample.xls")]'; put '[file-close()]'; put '[quit()]';run;

Page 20: Working Smarter, Not Harder with DDE: Did I Really Spend All That Time Just Formatting My Report?

As Hot As You Can TakeWrite formulas: put ‘[formula("=sum(R[-19]C:R[-14]C)/R38C20")]’; put ‘[formula("=sum(R12C20:R17C20)/R38C20")]’;

Combine with ODS html output into .xls Use activate(filename) and workbook.activate(sheet) to

choose between file sheet Use select(cellrange), copy(), paste()

Combine with Macro Variables Automatically change rows, columns with month Define columns as function of month Macros only resolve inside double quotes

put "[formula(""=sum(R[-19]C:R[-14]C)/R38C&col."")]";

Page 21: Working Smarter, Not Harder with DDE: Did I Really Spend All That Time Just Formatting My Report?

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

Page 22: Working Smarter, Not Harder with DDE: Did I Really Spend All That Time Just Formatting My Report?

Questions