Using SAS DDE to Control Excel



Similar documents
Microsoft Excel 2013: Macro to apply Custom Margins, Titles, Gridlines, Autofit Width & Add Macro to Quick Access Toolbar & How to Delete a Macro.

MS Excel. Handout: Level 2. elearning Department. Copyright 2016 CMS e-learning Department. All Rights Reserved. Page 1 of 11

Working with Macros and VBA in Excel 2007

NAVIGATION TIPS. Special Tabs

Basic Microsoft Excel 2007

Sample Table. Columns. Column 1 Column 2 Column 3 Row 1 Cell 1 Cell 2 Cell 3 Row 2 Cell 4 Cell 5 Cell 6 Row 3 Cell 7 Cell 8 Cell 9.

Macros in Word & Excel

Excel Level Two. Introduction. Contents. Exploring Formulas. Entering Formulas

Advanced Presentation Features and Animation

Excel 2007 Basic knowledge

Microsoft Excel Understanding the Basics

Using the Advanced Tier Data Collection Tool. A Troubleshooting Guide

Mail Merge Creating Mailing Labels 3/23/2011

Using DDE and SAS/Macro for Automated Excel Report Consolidation and Generation

3 What s New in Excel 2007

Spreadsheet - Introduction

Microsoft Excel 2010 Tutorial

Microsoft Excel Basics

Microsoft PowerPoint Tutorial

Guidelines for Completing the VDOT Form C 13CPM

Microsoft Excel Training - Course Topic Selections

Excel 2007: Basics Learning Guide

MS Word 2007 practical notes

Word 2007: Basics Learning Guide

WEBFOCUS QUICK DATA FOR EXCEL

LaGuardia Community College Thomson Ave, Long Island City, New York Created by ISMD s Dept. Training Team. Overview

MICROSOFT WORD TUTORIAL

Move between open workbooks. Display the print menu. Select whole spreadsheet. Microsoft Excel Keyboard Keys. General

Basic Excel Handbook

Excel basics. Before you begin. What you'll learn. Requirements. Estimated time to complete:

Getting Started with Excel Table of Contents

CREATING FORMAL REPORT. using MICROSOFT WORD. and EXCEL

Migrating to Excel 2010 from Excel Excel - Microsoft Office 1 of 1

Excel 2003 A Beginners Guide

Kingsoft Spreadsheet 2012

Excel 2003 Tutorial I

ECDL. European Computer Driving Licence. Spreadsheet Software BCS ITQ Level 2. Syllabus Version 5.0

User Guide. Opening secure from the State of Oregon Viewing birth certificate edits reports in MS Excel

PA Payroll Exercise for Intermediate Excel

Microsoft Word 2010 Tutorial

Excel 2007 Tutorials - Video File Attributes

PowerPoint 2007 Basics Website:

SPSS for Windows importing and exporting data

Choosing the Best Method to Create an Excel Report Romain Miralles, Clinovo, Sunnyvale, CA

Excel 2003 Tutorials - Video File Attributes

Microsoft Word 2013 Tutorial

Microsoft Word 2010 Prepared by Computing Services at the Eastman School of Music July 2010

Creating and Editing Workbooks. STUDENT LEARNING OUTCOMES (SLOs) After completing this chapter, you will be able to:

Q&As: Microsoft Excel 2013: Chapter 2

DOING MORE WITH WORD: MICROSOFT OFFICE 2010

Importing Excel Files Into SAS Using DDE Curtis A. Smith, Defense Contract Audit Agency, La Mirada, CA

Excel. Microsoft Office s spreadsheet application can be used to track. and analyze numerical data for display on screen or in printed

Clip Art in Office 2000

Microsoft Office Excel 2007 Key Features. Office of Enterprise Development and Support Applications Support Group

VBA PROGRAMMING FOR EXCEL FREDRIC B. GLUCK

HOUR 9. Formatting Worksheets to Look Great

Microsoft Word Revising Word Documents Using Markup Tools

Excel 2007 A Beginners Guide

Explore commands on the ribbon Each ribbon tab has groups, and each group has a set of related commands.

Handout: How to Use Excel 2010

Aspose.Cells Product Family

How to Use Excel for Law Firm Billing

paragraph(s). The bottom mark is for all following lines in that paragraph. The rectangle below the marks moves both marks at the same time.

Jadu Content Management Systems Web Publishing Guide. Table of Contents (click on chapter titles to navigate to a specific chapter)

How to Edit Your Website

Umbraco v4 Editors Manual

How to Use Excel 2007

Microsoft Excel 2010 Training

Excel 2007/2010 for Researchers. Jamie DeCoster Institute for Social Science Research University of Alabama. September 7, 2010

Word 2010: Mail Merge to with Attachments

Joomla Article Advanced Topics: Table Layouts

Microsoft Access 2010 handout

Microsoft Word 2013 Basics

Advanced Excel 10/20/2011 1

Tutorial Microsoft Office Excel 2003

Introduction to Microsoft Access 2003

Training Needs Analysis

Word processing software

Microsoft Excel 2010 Charts and Graphs

DESKTOP PRODUCTIVITY SOFTWARE

OX Spreadsheet Product Guide

Downloading RIT Account Analysis Reports into Excel

Creating Interactive PDF Forms

Module B. Key Applications Using Microsoft Office 2010

Using Adobe Dreamweaver CS4 (10.0)

Microsoft Excel 2013 Tutorial

To launch the Microsoft Excel program, locate the Microsoft Excel icon, and double click.

Site Maintenance. Table of Contents

CONTENTM WEBSITE MANAGEMENT SYSTEM. Getting Started Guide

In this session, we will explain some of the basics of word processing. 1. Start Microsoft Word 11. Edit the Document cut & move

Microsoft Excel 2010 Linking Worksheets and Workbooks

Microsoft Word 2010 Basics

Introduction to Microsoft Word 2003

Microsoft Outlook Introduction

Planning and Managing Projects with Microsoft Project Professional 2013

Microsoft Migrating to Word 2010 from Word 2003

MICROSOFT EXCEL 2011 MANAGE WORKBOOKS

Transcription:

Using SAS DDE to Control Excel George Zhu Alberta Health, Government of Alberta Edmonton SAS User Group Meeting April 15, 2015

1 DDE: Dynamic Data Exchange 2 Examples and Demonstration Demo 1: Import password protected Excel file Demo 2: Read data from specific cells Demo 3: Write date to specific cells Demo 4: Format Excel reports Demo 5: Run VBA macros 3 Troubleshooting

What is DDE DDE stands Dynamic Data Exchange DDE is communication protocol that lets PC-based (Microsoft) applications talk to each other Excel and Word are DDE-compatible applications The DDE mechanism in SAS enables SAS to control Excel or Word

Why DDE Good for automation: Basically, what you can do with Excel/Word using keyboard and mouse can be replicated programatically in SAS Only base SAS and MS Excel/Word are needed Most useful feature - customize the Excel worksheet or Word document programatically DDE is far from obsolete - The backward compatibility requirement guarantees it is supported in later versions of Excel/Word You can run VBA through DDE

Why DDE is not popular DDE can be quite complicated and tedious to program Excel and Word use different programming languages for DDE Excel: X4ML (Excel 4 Macro Language) - New features (like merge cells) after Excel 4 are not supported Word: WordBASIC (a subset of MS QuickBASIC programming language) Both are now replaced by VBA (Visual Basic for Applications), but VBA does not support DDE protocol

Examples and Demonstration

Get Excel/Word running To use DDE, Server application (Excel/Word) needs to be fully up and running SAS gains control after Excel/Word launching For SAS to gain control after launching Excel/Word, turn off the XWAIT and XSYNC options: options noxwait noxsync;

Launch Excel/Word There are several ways to get Excel or Word running from within SAS. Use X command X "Start Excel"; Use %sysexec statement Without opening an existing workbook %sysexec "start excel"; Opening an existing Excel workbook %sysexec "examples.xlsx"; Let SAS wait for a few seconds until Excel is fully running: data null ; rc=sleep(15); * wait for 15 seconds; run;

DDE syntax: Doublet vs Triplet style DDE is specified through the Filename statement. Two DDE formats: Doublet: - Main menu operations, such as file operations, worksheet selection, cell range selection, etc. filename sas2xl dde "excel system"; For doublet, it is always excel system Triplet: - for accessing specific cell ranges filename sas3xl dde "excel [examples.xlsx]sheet1!r1c1:r20c2" <DDE-options>;

Demo 1: Import password protected Excel file Example 1: Import from password protected Excel file A DDE Solution: Start Excel without opening the excel file Use open command to open the excel file. The syntax of the open command: OPEN(file text, update links, read only, format, prot pwd, write res pwd,...) Use save.as command to save the excel file without the password. The syntax of the save.as command: SAVE.AS(file text, type num, prot pwd, backup, write res pwd, read only rec) Import data from the password removed excel file Delete the password removed excel file

Demo 1: Import password protected Excel file Example 1: Import from password protected Excel file Make sure the file extension name matches type num when saving a new file: SAVE.AS(file text, type num, prot pwd, backup, write res pwd, read only rec) 51:.xlsx (Excel 2007-2013, without macro) 52:.xlsm (Excel 2007-2013, with or without macro) 56:.xls (Excel 97-2003 format)

Demo 2: Read data from specific cells Example 2: Read data from Excel in a specific range Use DDE triplet-format to specific the range (notice the notab option): filename exldata dde "excel phds!r2c1:r7c7" notab; Then use the infile statement with delimiter= 09 x (Tab key) infile exldata delimiter= 09 x dsd; Advantages of this data import method: Can handles mixed data type (numerical and character) Can import from irregular spreadsheet format

Demo 3: Write date to specific cells Example 3: Write data to specific cells How? Use DDE triplet to specify output target places Need to use the notab option Use Tab key (ASCII value 09 x) to put data in next cell Remember SAS sends formatted value to Excel Advantages of using DDE method: Only specific cell ranges are being updated Preserves custom format in the worksheet

Demo 4: Format Excel reports Example 4: Formatting Excel Worksheet/Cells Frequently used formatting operations: Font Formatting: FORMAT.FONT(name text, size num, bold, italic, underline, strike, color, outline, shadow) Alignment ALIGNMENT(horiz align, wrap, vert align, orientation, add indent) Some values for horiz align, and vert align: 1: General 2: Left 3: Center 4: Right

Demo 4: Format Excel reports Example 4: Formatting Excel Worksheet/Cells Set column width COLUMN.WIDTH(width num, reference, standard, type num, standard num) The important parameter is type num: 1: hide the column with width=0 2: Unhide the column 3: Set column width to best-fit Freeze panel freeze.panes(true/false,col split,row split) col split: Number of columns (from left) to be freezed row split: Number of rows (from top) to be freezed

Demo 4: Format Excel reports Example 4: Formatting Excel Worksheet/Cells Borders - for drawing tables BORDER(outline, left, right, top, bottom, shade, outline color, left color, right color, top color, bottom color) Values for the line parameters: 0: No border 1: Thin line 2: Medium line 3: Dashed line 4: Dotted line 5: Thick line 6: Double line 7: Hairline

Demo 5: Run VBA macros Example 5: Running VBA macros Use the RUN command: Equivalent to click the Run button in the Macro dialog box: put [run("vab Macro Name")] ; Make sure to enable VBA Macro function in Excel before running the SAS codes. Demonstration: 1. Recode a macro for adding a title row 2. Remove the title row 3. From SAS run the DDE code to add the title row by revoking the recoded macro

DDE trouble shooting Common issue: DDE session not ready Excel is not fully up and running when SAS sends control to Excel Syntax error with X4ML statements Working wiht macro variables

Questions Comments & Questions?