sas >> Problem reading Excel data containing spaces w/ dde

by Howard_Schreier » Wed, 28 Jul 2004 04:17:31 GMT

That should work in this case, assuming that there are no multiple spaces
within the character strings.

However, there would be a problem if there were more columns to read after
DESC. They would get eaten up.

I suggest coding the NOTAB option on the FILENAME statement and the
DLM='09'x and DSD options on the INFILE.

On Tue, 27 Jul 2004 08:58:23 -0400, Nat Wooding < XXXX@XXXXX.COM >

>Try adding an & after the variable desc .
>Nat Wooding
>data a;
>length desc $255.;
>input Code Recode Desc &;
>1 2 Value1
>2 2 Value1
>3 6 Value Other
>4 6 Value Other
>5 4 Value2
>proc print;run;
> Mark Biek
> <markb@STEVENSONC To: SAS-
> Sent by: "SAS(r) Subject: Problem reading
Excel data containing spaces w/ dde
> Discussion"
> 07/27/04 08:47 AM
> Please respond to
> Mark Biek
>I have some data in Excel that looks like this:
>Code Recode Desc
>1 2 Value1
>2 2 Value1
>3 6 Value Other
>4 6 Value Other
>5 4 Value2
>Which I'm trying to read in using the following code:
>filename q2 dde "excel|q2!r2c2:r42c4";
>data rc_q2;
> length desc $255.;
> infile q2;
> input code recode desc;
>It works except the Desc field is truncated whenever there is a space
>so Code 3 ends up being:
>3 6 Value
>instead of
>3 6 Value Other
>What do I need to do to get the whole field?
>Mark Biek
>The Stevenson Company
>8700 Westport Rd. Ste. 200
>Louisville, KY 40242-3100
>(502) 429-9060 ext 251

Similar Threads

1. DDE : problem read sheets whose name ends with a space

Hi folks,

My source data is delivered in Excel format. I read this in using DDE.
I have recently discovered a problem when trying to read from a
worksheet whose name ends in a space. The space is no recognised in the
filename statement. Resulting in the following error message -

ERROR: Physical file does not exist, Excel|[TESTSHEET.xls]Sheet1 !r1c1.

Here is some example code -

FILENAME XL DDE 'Excel|[TESTSHEET.xls]sheet1 !r1c1';

DATA test;
  input value $200.;

Where a sheet is not protected I can solve this by running via DDE a
VBA macro which removes the trailing space. However many files are
delivered with worksheet protection.

Any ideas why the filename is not recognised ?

many thanks in advance


2. Problem of containing space in data

3. how to read DOS directories which contain spaces


I have a problem reading DOS directories that contain spaces:
example code:

any ideas on this?

%let pdriver=C:\SasDev\pgm directories\p101 programs;

%let ddir=&pdriver||' ';

filename DIRLIST pipe "dir &ddir /s";

data _in_;

length dir_info $256;

infile dirlist length=reclen;

input dir_info $varying256. reclen;


4. Excel and DDE CPS Plus serial data acquisition problem - Excel

5. DDE Excel problem -- dealing with multiple Excel sessions

Everything works great unless there happens to be another instance of
Excel running, in which case everything turns into chaos.  I use a
standard DDE routine to open an Excel session (see below).  The
problems occur when I try to write to Excel further on down in the
program -- I end up writing results to the wrong Excel session, or
worse.  Any suggestions?

%macro openExcel();
      options noxsync noxwait;
      filename sas2xl dde 'excel|system'; * reference to open/close
excel ;
      data _null_;
            length fid rc start stop time 8;
            if (fid le 0) then do;
                  rc=system('start excel');
                  do while (fid le 0);
                        if (time ge stop) then fid=1;
%mend openExcel;

6. Reading complete Excel using DDE code - Excel

7. read excel through dde

    id  type label 98 Binary The occurrence of a "HUMAN IMMUNODEFICIENCY
VIRUS" claim during modeling year  167 Binary The occurrence of a "METABOLIC
COMPLICATIONS" claim due to diabetes during the modeling year
I have above excel file with 3 columns. I want ot read it to sas throught
dde. (We do not have import sas modules)
I used following code:

options noxwait noxsync;

x *'"c:\program files\microsoft office\office10\excel.exe"'*;

data _null_;




/* open Excel workbook */

/*"N:\PM\PM_RF\CSVs\definitionT.csv" */


filename ddecmd dde *'excel|system'*;

data _null_;

file ddecmd;

put *'[FILE-OPEN("N:\PM\PM_RF\CSVs\definitionT.xls")]'*;



/* specify desired Excel worksheet cell range */


filename xlin DDE *'excel|definitionT!r2c1:r5c2'*;



/* read Excel files using DDE into SAS data set*/


data test;

infile xlin dlm=*'09'x* notab missover dsd;

informat id 8. type $20. label $200.;

input id type label;

format id 8. type $8. label $200.;



/* close Excel workbook and close Excel */

data _null_;

file xlin;

put *'[FILE-CLOSE("N:\PM\PM_RF\CSVs\definitionT.xls")]'*;

put *'[QUIT()];


This code can read "id" and "type" into sas dataset but failed to read
"label".(the varible name is in the resulting sas dataset test, but the
contents of lable is not there.

How can I fix this problem?



8. "Excel Data Problem - Space Between Word" - Excel