BookmarkSubscribeRSS Feed
Peter_C
Rhodochrosite | Level 12

DDE can read that data!

I looked at the first two options in the excel dialog

Untitled.png

As an XML table it creates a schema and a new workboot with references, like Excel|[Book2]Sheet1

After selecting the data area and copying to the clipboard, SAS sees the DDE triplet as

'Excel|[Book2]Sheet1!R1C1:R37C6'

When selecting "As a read-only workbook", the object references retain more of the original names and the clipboard triplet becomes

Excel|http://www.w3schools.com/xml/[plant_catalog.xml]plant_catalog!R1C1:R38C7

Once you open the XML as a readonly workbook in excel, a sufficient data step to read this from base SAS on windows, is

data ;

infile

'Excel|http://www.w3schools.com/xml/[plant_catalog.xml]plant_catalog!R1C1:R38C7'

         device=dde notab lrecl=1000 dsd dlm='09'x truncover ;

input (col1-col8)($) ;

run;

Those who seek an even more general approach can remove the "row reference" allowing DDE to load as many rows as are present and up to 255 columns, with the triplet

Excel|http://www.w3schools.com/xml/[plant_catalog.xml]plant_catalog!C1:C255

The data step above provides just the first 8 characters of each column, but enough to demo the principle. To load wider, change the ($) in the INPUT statement to (:$30.)

Always use TRUNCOVER to deal with short lines and DSD to skip empty cells

It does show interesting differences when comparing these two presentations from excel.

It also points out what we might hope for in the next release of improvements to SAS XML LIBNAME engines

That "we can" does not mean that "we should", as the number of ways that DDE can disappoint are many!

ThomasCox
SAS Employee

Thought I should update this to point out that the AUTOMAP option has indeed been added to the SAS XML Libname engine. See SAS(R) 9.4 XML LIBNAME Engine: User's Guide

While automapping make  pretty decent "best guess" at how the data should be structured, it may not always bring in data structured the way you like.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 16 replies
  • 4752 views
  • 0 likes
  • 7 in conversation