Hi, I changed to top X System Option to options noxwait noxsync ; It worked correctly three times, then it failed. See log below. It seems to me to be a timing issue on opening Excel. That is why I put in the SLEEP data step. Nancy ____________________________________________________ NOTE: Copyright (c) 2002-2008 by SAS Institute Inc., Cary, NC, USA. NOTE: SAS (r) Proprietary Software 9.2 (TS2M3) Licensed to CENSUS BUREAU FOUNDATION WNDW, Site 70047657. NOTE: This session is executing on the XP_PRO platform. NOTE: SAS initialization used: real time 2.79 seconds cpu time 1.60 seconds 1 OPTIONS SYMBOLGEN MPRINT; 2 options noxwait noxsync ; 3 4 %global filnme mypath newdrive; 5 6 %MACRO fdate(fmt); 7 %global fdate; 8 data _null_; 9 call symputx("fdate",put("&sysdate"d,&fmt)); 10 run; 11 %MEND fdate; 12 %fdate(worddate.) /* Execute the macro */ MPRINT(FDATE): data _null_; SYMBOLGEN: Macro variable SYSDATE resolves to 24JUN11 SYMBOLGEN: Macro variable FMT resolves to worddate. MPRINT(FDATE): call symputx("fdate",put("24JUN11"d,worddate.)); MPRINT(FDATE): run; NOTE: DATA statement used (Total process time): real time 0.04 seconds cpu time 0.01 seconds SYMBOLGEN: Macro variable FDATE resolves to June 24, 2011 13 %put *** This program ran on: &fdate; *** This program ran on: June 24, 2011 14 15 16 %let filnme = %sysget(SAS_EXECFILENAME); 17 %let xpath = %sysget(SAS_EXECFILEPATH); 18 %let mypath = M:\ADC-P\CPSPB; 19 20 /* Determine the current drive and directory that is being used. */ 21 %let drvlen = %index(&mypath,\CPSPB); SYMBOLGEN: Macro variable MYPATH resolves to M:\ADC-P\CPSPB 22 %let newdrive= %substr(&mypath,1,&drvlen - 1)\CPSPB\; SYMBOLGEN: Macro variable MYPATH resolves to M:\ADC-P\CPSPB SYMBOLGEN: Macro variable DRVLEN resolves to 9 23 24 25 /* start Excel */ 26 * %include "&mypath\opnexcel.sas"; 27 filename cmdexcel DDE 'EXCEL|SYSTEM'; 28 /**********************************************************************/ 29 /* Data step to start Excel if it is not already open */ 30 /**********************************************************************/ 31 32 data _null_; 33 fid = fopen('cmdexcel','S'); /* Check if Excel is open */ 34 if fid le 0 then do; /* Open via Windows registry */ 35 rc = system("Start Excel"); /* DOS command to open Excel */ 36 start = datetime(); /* Note start time */ 37 stop = start + 5; /* Max time to try opening */ 38 do while (fid le 0); /* Loop while Excel opens */ 39 fid = fopen('cmdexcel','S'); /* Check if Excel is open */ 40 time = datetime(); /* Reset current time */ 41 if time ge stop then fid = time; /* Set FID to terminate loop */ 42 end; /* do while (fid le 0) */ 43 end; /* Open via Windows registry */ 44 rc = fclose(fid); /* Close fileopen on Excel */ 45 run; NOTE: DATA statement used (Total process time): real time 5.15 seconds cpu time 0.23 seconds 46 47 48 *create macro variables with the Excel file names; 49 data _null_; 50 call symput('macrfile',"'"|| 51 '[open("'||"&newdrive"||'Macros\Chdaily_test_.xlsm")]'||"';"); SYMBOLGEN: Macro variable NEWDRIVE resolves to M:\ADC-P\CPSPB\ 52 run; NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds 53 54 /* Make it wait some while Excel opens */ 55 data _null_; 56 rc=sleep(20); 57 run; NOTE: DATA statement used (Total process time): real time 20.03 seconds cpu time 0.03 seconds 58 59 /**********************************************/ 60 /* OPEN THE EXCEL FILE CONTAINING THE MACRO. */ 61 /**********************************************/ 62 data _null_; 63 file cmdexcel; SYMBOLGEN: Macro variable MACRFILE resolves to '[open("M:\ADC-P\CPSPB\Macros\Chdaily_test_.xlsm")]'; 64 put ¯file; *open the file containing the macro; 65 run; ERROR: File is in use, EXCEL|SYSTEM. NOTE: The SAS System stopped processing this step because of errors. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds
... View more