comp.soft-sys.sas - The SAS statistics package.
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; infile XL DDE NOTAB TRUNCOVER; input value $200.; RUN; 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 Richard
Group: 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; run;
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; fid=fopen('sas2xl','s'); if (fid le 0) then do; rc=system('start excel'); start=datetime(); stop=start+10; do while (fid le 0); fid=fopen('sas2xl','s'); time=datetime(); if (time ge stop) then fid=1; end; end; rc=fclose(fid); run; %mend openExcel;
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_; x=sleep(5); run; *; /* 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")]'*; run; *; /* specify desired Excel worksheet cell range */ *; filename xlin DDE *'excel|definitionT!r2c1:r5c2'*; run; *; /* 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.; run; *; /* close Excel workbook and close Excel */ data _null_; file xlin; put *'[FILE-CLOSE("N:\PM\PM_RF\CSVs\definitionT.xls")]'*; put *'[QUIT()]; run; 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? Thanks. Jeff *