<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic sas2excl macro won't start excel in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sas2excl-macro-won-t-start-excel/m-p/75944#M16376</link>
    <description>Below is a macro taken from a SUGI event years ago and modified some.  It opens up excel and dumps in SAS data with options for various tasks.&lt;BR /&gt;
&lt;BR /&gt;
In starting a new contract at a new site I can no longer get the macro to open up excel.  It must be open before running the macro.  I know somewhere you need to set a path in windows or something.  It's been too long ago to remember.  Anyone got any ideas?&lt;BR /&gt;
&lt;BR /&gt;
/*******************************************************************\&lt;BR /&gt;
| Copyright (C) 1997 by SAS Institute Inc., Cary, NC, USA.          |&lt;BR /&gt;
|                                                                   |&lt;BR /&gt;
| SAS (R) is a registered trademark of SAS Institute Inc.           |&lt;BR /&gt;
|                                                                   |&lt;BR /&gt;
| SAS Institute does not assume responsibility for the accuracy of  |&lt;BR /&gt;
| any material presented in this file.                              |&lt;BR /&gt;
\*******************************************************************/&lt;BR /&gt;
&lt;BR /&gt;
/* SAS2EXCL.sas, example from SUGI 17 proceedings page 117            */&lt;BR /&gt;
/* will send via dde from sas to excel and retain column headings     */&lt;BR /&gt;
&lt;BR /&gt;
/* Enhancements Log - all completed by Boaz Wong (604)432-5441&lt;BR /&gt;
&lt;BR /&gt;
   1) Modified to correct errors in original code downloaded from SAS&lt;BR /&gt;
&lt;BR /&gt;
   2) Revised to invoke EXCEL97&lt;BR /&gt;
&lt;BR /&gt;
   3) Resolved truncation problems caused by extra long lines of data&lt;BR /&gt;
&lt;BR /&gt;
   4) New parameters were added to allow saving to a specific directory&lt;BR /&gt;
&lt;BR /&gt;
   5) New Capability to auto-detect whether Excel is running or not&lt;BR /&gt;
&lt;BR /&gt;
   6) More parameters added:&lt;BR /&gt;
        a) option to have no labels (use colhead=NONE)&lt;BR /&gt;
        b) specific starting point of block of cells to insert into&lt;BR /&gt;
        c) sortby parameter - order that variables will be inserted&lt;BR /&gt;
&lt;BR /&gt;
   7) Multiple pathnames are searched for Excel differences between&lt;BR /&gt;
        Win95 and Win98 installations&lt;BR /&gt;
&lt;BR /&gt;
   &lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt; Updated LRECL of Excel file to 2048 - October 25, 2000&lt;BR /&gt;
&lt;BR /&gt;
   9) Added code to remove trailing blank&lt;BR /&gt;
&lt;BR /&gt;
   10) Updated LRECL of Excel file to 2560 - July 5, 2001&lt;BR /&gt;
&lt;BR /&gt;
   11) Updated LRECL of Excel file to 2816 - Jan 14, 2002&lt;BR /&gt;
*/&lt;BR /&gt;
&lt;BR /&gt;
options noxwait noxsync nomprint nosymbolgen;&lt;BR /&gt;
%macro sas2excl (start=Y,     /* No longer required */&lt;BR /&gt;
                 close=N,     /* closes excel if you desire use 'Y' to close */&lt;BR /&gt;
                 new=Y,       /* creates new workbook */&lt;BR /&gt;
                 open=N,      /* opens existing workbook */&lt;BR /&gt;
                 clear=N,     /* clear worksheet prior to populating */&lt;BR /&gt;
                 colhead=NAME, /* change to LABEL to have columns use labels */&lt;BR /&gt;
                 sasin=_last_,   /* SAS dataset */&lt;BR /&gt;
                 exdirin=,              /* Excel directory */&lt;BR /&gt;
                 excelbk=[BOOK1],       /* Excel workbook - if existing-add .xls */&lt;BR /&gt;
                 excelin=BOOK1,         /* Excel file */&lt;BR /&gt;
                 excelsh=SHEET1,        /* Excel sheet */&lt;BR /&gt;
                 exdirout=,             /* Excel directory */&lt;BR /&gt;
                 excelout=,&lt;BR /&gt;
                 st_row=1,              /*  Starting row of Excel Block of data */&lt;BR /&gt;
                 st_col=1,     /*  Starting column of Excel Block of data */&lt;BR /&gt;
                 sortby=       /* possible values: varnum, name, label */&lt;BR /&gt;
);&lt;BR /&gt;
&lt;BR /&gt;
%if %upcase(&amp;amp;colhead) ne NAME and&lt;BR /&gt;
    %upcase(&amp;amp;colhead) ne LABEL and&lt;BR /&gt;
    %upcase(&amp;amp;colhead) ne NONE %then %do;&lt;BR /&gt;
    data _null_;&lt;BR /&gt;
      error 'Invalid parameter error: COLHEAD=' "&amp;amp;colhead";&lt;BR /&gt;
      abort;&lt;BR /&gt;
    run;&lt;BR /&gt;
%end;&lt;BR /&gt;
&lt;BR /&gt;
%if %sysfunc(exist(&amp;amp;sasin)) %then %do;&lt;BR /&gt;
   		data _null_;&lt;BR /&gt;
    		if 0 then set &amp;amp;sasin nobs=count;&lt;BR /&gt;
 			if count = 0 then do; &lt;BR /&gt;
			  	error 'Invalid Dataset error: ' "&amp;amp;sasin" ' is empty';&lt;BR /&gt;
       			abort;&lt;BR /&gt;
    		end;&lt;BR /&gt;
			else stop;&lt;BR /&gt;
 		run;&lt;BR /&gt;
       %end;&lt;BR /&gt;
       %else %do;&lt;BR /&gt;
       data _null_;&lt;BR /&gt;
       		error 'Invalid Dataset error: ' "&amp;amp;sasin" ' does not exist';&lt;BR /&gt;
       		abort;&lt;BR /&gt;
       run;&lt;BR /&gt;
%end;&lt;BR /&gt;
&lt;BR /&gt;
%if %upcase(&amp;amp;colhead) eq NONE %then %do;&lt;BR /&gt;
        %let offset=0;&lt;BR /&gt;
%end;&lt;BR /&gt;
%else %do;&lt;BR /&gt;
        %let offset=1;&lt;BR /&gt;
%end;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
filename cmdexcel dde 'excel|system';&lt;BR /&gt;
&lt;BR /&gt;
%let fid=%sysfunc(fopen(cmdexcel,S));&lt;BR /&gt;
%if &amp;amp;fid gt 0 %then %do;&lt;BR /&gt;
    %let rc=%sysfunc(fclose(&amp;amp;fid));&lt;BR /&gt;
%end;&lt;BR /&gt;
%else %do;&lt;BR /&gt;
   %let expath='C:\Progra~1\Micros~2\Office\EXCEL.EXE';&lt;BR /&gt;
   %if %sysfunc(fileexist(&amp;amp;EXPATH)) %then %do;&lt;BR /&gt;
        x &amp;amp;expath;&lt;BR /&gt;
        data _null_;&lt;BR /&gt;
           x=sleep(5);&lt;BR /&gt;
        run;&lt;BR /&gt;
   %end;&lt;BR /&gt;
     %else %do;&lt;BR /&gt;
        %let expath='C:\Progra~1\Micros~1\Office\EXCEL.EXE';&lt;BR /&gt;
        %if %sysfunc(fileexist(&amp;amp;EXPATH)) %then %do;&lt;BR /&gt;
                x &amp;amp;expath;&lt;BR /&gt;
                data _null_;&lt;BR /&gt;
                   x=sleep(5);&lt;BR /&gt;
                run;&lt;BR /&gt;
        %end;&lt;BR /&gt;
        %else %do;&lt;BR /&gt;
        %let expath='C:\Program Files\Microsoft Office\OFFICE11';&lt;BR /&gt;
        %if %sysfunc(fileexist(&amp;amp;EXPATH)) %then %do;&lt;BR /&gt;
                x &amp;amp;expath;&lt;BR /&gt;
                data _null_;&lt;BR /&gt;
                   x=sleep(6);&lt;BR /&gt;
                run;&lt;BR /&gt;
        %end;&lt;BR /&gt;
        %else %do;&lt;BR /&gt;
        %let expath='C:\Progra~1\Msoffi~1\Office\EXCEL.EXE';&lt;BR /&gt;
        %if %sysfunc(fileexist(&amp;amp;EXPATH)) %then %do;&lt;BR /&gt;
                x &amp;amp;expath;&lt;BR /&gt;
                data _null_;&lt;BR /&gt;
                   x=sleep(10);&lt;BR /&gt;
                run;&lt;BR /&gt;
        %end;&lt;BR /&gt;
       %else %do;&lt;BR /&gt;
             data _null_;&lt;BR /&gt;
                  error 'Error: Excel could not be found';&lt;BR /&gt;
                  abort;&lt;BR /&gt;
             run;&lt;BR /&gt;
       %end;&lt;BR /&gt;
	  %end;&lt;BR /&gt;
     %end;&lt;BR /&gt;
   %end;&lt;BR /&gt;
%end;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%if &amp;amp;new eq Y %then %do;&lt;BR /&gt;
    data _null_;&lt;BR /&gt;
      file cmdexcel;&lt;BR /&gt;
      put "[new]";&lt;BR /&gt;
    run;&lt;BR /&gt;
&lt;BR /&gt;
    filename cmdexcs dde 'excel|system!selection';&lt;BR /&gt;
&lt;BR /&gt;
    data _null_;&lt;BR /&gt;
      length path $ 80;&lt;BR /&gt;
      infile cmdexcs pad dsd notab dlm='09'x;&lt;BR /&gt;
      input path $ @@;&lt;BR /&gt;
      i = index(path,']');&lt;BR /&gt;
      j = index(path,'!');&lt;BR /&gt;
      workbook = substr(path,1,i);&lt;BR /&gt;
      sheet = substr(path,i+1,j-i-1);&lt;BR /&gt;
      call symput('excelbk',trim(workbook));&lt;BR /&gt;
      call symput('excelsh',trim(sheet));&lt;BR /&gt;
    run;&lt;BR /&gt;
&lt;BR /&gt;
%end;&lt;BR /&gt;
&lt;BR /&gt;
%if &amp;amp;open eq Y %then %do;&lt;BR /&gt;
    data _null_;&lt;BR /&gt;
      file cmdexcel;&lt;BR /&gt;
      put "[open(""&amp;amp;exdirin&amp;amp;excelin"")]";&lt;BR /&gt;
    run;&lt;BR /&gt;
%end;&lt;BR /&gt;
&lt;BR /&gt;
proc contents data=&amp;amp;sasin noprint&lt;BR /&gt;
               out=conts(keep=nobs NAME label format formatl formatd type varnum);&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%if &amp;amp;SORTBY ne %then %do;&lt;BR /&gt;
    proc sort data=CONTS;&lt;BR /&gt;
      by &amp;amp;SORTBY;&lt;BR /&gt;
    run;&lt;BR /&gt;
%end;&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
  set conts end=eof;&lt;BR /&gt;
   if label eq '' then&lt;BR /&gt;
      label=NAME;&lt;BR /&gt;
   call symput('col'||left(_n_),trim(NAME));&lt;BR /&gt;
   call symput('lab'||left(_n_),trim(LABEL));&lt;BR /&gt;
&lt;BR /&gt;
   if eof then do;&lt;BR /&gt;
   call symput('columns',trim(left(_n_)));&lt;BR /&gt;
   call symput('rows',trim(left(nobs)));&lt;BR /&gt;
   end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%if %upcase(&amp;amp;colhead) ne NONE %then %do;&lt;BR /&gt;
        filename excel dde "excel|&amp;amp;exdirin&amp;amp;excelbk&amp;amp;excelsh.!r&amp;amp;st_row.c&amp;amp;st_col:r&amp;amp;st_row.c%eval(&amp;amp;columns+&amp;amp;st_col)" lrecl=2816 notab;&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
  file excel;&lt;BR /&gt;
  hextab='09'x;&lt;BR /&gt;
  %if %upcase(&amp;amp;colhead) eq NAME %then %do;&lt;BR /&gt;
    put %do i=1 %to &amp;amp;columns;&lt;BR /&gt;
    "%trim(&amp;amp;&amp;amp;col&amp;amp;i)"  hextab +(-1)&lt;BR /&gt;
    %end;&lt;BR /&gt;
    ;&lt;BR /&gt;
  %end;&lt;BR /&gt;
&lt;BR /&gt;
  %else %if %upcase(&amp;amp;colhead) eq LABEL %then %do;&lt;BR /&gt;
    put %do i=1 %to &amp;amp;columns;&lt;BR /&gt;
    "%trim(&amp;amp;&amp;amp;lab&amp;amp;i)"  hextab +(-1)&lt;BR /&gt;
    %end;&lt;BR /&gt;
    ;&lt;BR /&gt;
  %end;&lt;BR /&gt;
run;&lt;BR /&gt;
%end;&lt;BR /&gt;
&lt;BR /&gt;
filename excel dde "excel|&amp;amp;exdirin&amp;amp;excelbk&amp;amp;excelsh.!r%eval(&amp;amp;st_row+&amp;amp;offset)c&amp;amp;st_col:R%eval(&amp;amp;st_row+&amp;amp;rows+&amp;amp;offset)C%eval(&amp;amp;st_col+&amp;amp;columns)" lrecl=2816 notab;&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
  set &amp;amp;sasin;&lt;BR /&gt;
  hextab='09'x;&lt;BR /&gt;
  file excel;&lt;BR /&gt;
  put %do i=1 %to &amp;amp;columns;&lt;BR /&gt;
    %trim(&amp;amp;&amp;amp;col&amp;amp;i) +(-1) hextab +(-1)&lt;BR /&gt;
    %end;&lt;BR /&gt;
    ;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%if &amp;amp;excelout ne %then %do;&lt;BR /&gt;
    data _null_;&lt;BR /&gt;
      file cmdexcel;&lt;BR /&gt;
      put "[save.as(""&amp;amp;exdirout&amp;amp;excelout"")]";&lt;BR /&gt;
    run;&lt;BR /&gt;
%end;&lt;BR /&gt;
&lt;BR /&gt;
%if %upcase(&amp;amp;close) eq Y %then %do;&lt;BR /&gt;
    data _null_;&lt;BR /&gt;
      file cmdexcel;&lt;BR /&gt;
      put "[close]";&lt;BR /&gt;
    run;&lt;BR /&gt;
%end;&lt;BR /&gt;
%mend sas2excl;</description>
    <pubDate>Thu, 15 Oct 2009 16:09:58 GMT</pubDate>
    <dc:creator>paulsparrow</dc:creator>
    <dc:date>2009-10-15T16:09:58Z</dc:date>
    <item>
      <title>sas2excl macro won't start excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas2excl-macro-won-t-start-excel/m-p/75944#M16376</link>
      <description>Below is a macro taken from a SUGI event years ago and modified some.  It opens up excel and dumps in SAS data with options for various tasks.&lt;BR /&gt;
&lt;BR /&gt;
In starting a new contract at a new site I can no longer get the macro to open up excel.  It must be open before running the macro.  I know somewhere you need to set a path in windows or something.  It's been too long ago to remember.  Anyone got any ideas?&lt;BR /&gt;
&lt;BR /&gt;
/*******************************************************************\&lt;BR /&gt;
| Copyright (C) 1997 by SAS Institute Inc., Cary, NC, USA.          |&lt;BR /&gt;
|                                                                   |&lt;BR /&gt;
| SAS (R) is a registered trademark of SAS Institute Inc.           |&lt;BR /&gt;
|                                                                   |&lt;BR /&gt;
| SAS Institute does not assume responsibility for the accuracy of  |&lt;BR /&gt;
| any material presented in this file.                              |&lt;BR /&gt;
\*******************************************************************/&lt;BR /&gt;
&lt;BR /&gt;
/* SAS2EXCL.sas, example from SUGI 17 proceedings page 117            */&lt;BR /&gt;
/* will send via dde from sas to excel and retain column headings     */&lt;BR /&gt;
&lt;BR /&gt;
/* Enhancements Log - all completed by Boaz Wong (604)432-5441&lt;BR /&gt;
&lt;BR /&gt;
   1) Modified to correct errors in original code downloaded from SAS&lt;BR /&gt;
&lt;BR /&gt;
   2) Revised to invoke EXCEL97&lt;BR /&gt;
&lt;BR /&gt;
   3) Resolved truncation problems caused by extra long lines of data&lt;BR /&gt;
&lt;BR /&gt;
   4) New parameters were added to allow saving to a specific directory&lt;BR /&gt;
&lt;BR /&gt;
   5) New Capability to auto-detect whether Excel is running or not&lt;BR /&gt;
&lt;BR /&gt;
   6) More parameters added:&lt;BR /&gt;
        a) option to have no labels (use colhead=NONE)&lt;BR /&gt;
        b) specific starting point of block of cells to insert into&lt;BR /&gt;
        c) sortby parameter - order that variables will be inserted&lt;BR /&gt;
&lt;BR /&gt;
   7) Multiple pathnames are searched for Excel differences between&lt;BR /&gt;
        Win95 and Win98 installations&lt;BR /&gt;
&lt;BR /&gt;
   &lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt; Updated LRECL of Excel file to 2048 - October 25, 2000&lt;BR /&gt;
&lt;BR /&gt;
   9) Added code to remove trailing blank&lt;BR /&gt;
&lt;BR /&gt;
   10) Updated LRECL of Excel file to 2560 - July 5, 2001&lt;BR /&gt;
&lt;BR /&gt;
   11) Updated LRECL of Excel file to 2816 - Jan 14, 2002&lt;BR /&gt;
*/&lt;BR /&gt;
&lt;BR /&gt;
options noxwait noxsync nomprint nosymbolgen;&lt;BR /&gt;
%macro sas2excl (start=Y,     /* No longer required */&lt;BR /&gt;
                 close=N,     /* closes excel if you desire use 'Y' to close */&lt;BR /&gt;
                 new=Y,       /* creates new workbook */&lt;BR /&gt;
                 open=N,      /* opens existing workbook */&lt;BR /&gt;
                 clear=N,     /* clear worksheet prior to populating */&lt;BR /&gt;
                 colhead=NAME, /* change to LABEL to have columns use labels */&lt;BR /&gt;
                 sasin=_last_,   /* SAS dataset */&lt;BR /&gt;
                 exdirin=,              /* Excel directory */&lt;BR /&gt;
                 excelbk=[BOOK1],       /* Excel workbook - if existing-add .xls */&lt;BR /&gt;
                 excelin=BOOK1,         /* Excel file */&lt;BR /&gt;
                 excelsh=SHEET1,        /* Excel sheet */&lt;BR /&gt;
                 exdirout=,             /* Excel directory */&lt;BR /&gt;
                 excelout=,&lt;BR /&gt;
                 st_row=1,              /*  Starting row of Excel Block of data */&lt;BR /&gt;
                 st_col=1,     /*  Starting column of Excel Block of data */&lt;BR /&gt;
                 sortby=       /* possible values: varnum, name, label */&lt;BR /&gt;
);&lt;BR /&gt;
&lt;BR /&gt;
%if %upcase(&amp;amp;colhead) ne NAME and&lt;BR /&gt;
    %upcase(&amp;amp;colhead) ne LABEL and&lt;BR /&gt;
    %upcase(&amp;amp;colhead) ne NONE %then %do;&lt;BR /&gt;
    data _null_;&lt;BR /&gt;
      error 'Invalid parameter error: COLHEAD=' "&amp;amp;colhead";&lt;BR /&gt;
      abort;&lt;BR /&gt;
    run;&lt;BR /&gt;
%end;&lt;BR /&gt;
&lt;BR /&gt;
%if %sysfunc(exist(&amp;amp;sasin)) %then %do;&lt;BR /&gt;
   		data _null_;&lt;BR /&gt;
    		if 0 then set &amp;amp;sasin nobs=count;&lt;BR /&gt;
 			if count = 0 then do; &lt;BR /&gt;
			  	error 'Invalid Dataset error: ' "&amp;amp;sasin" ' is empty';&lt;BR /&gt;
       			abort;&lt;BR /&gt;
    		end;&lt;BR /&gt;
			else stop;&lt;BR /&gt;
 		run;&lt;BR /&gt;
       %end;&lt;BR /&gt;
       %else %do;&lt;BR /&gt;
       data _null_;&lt;BR /&gt;
       		error 'Invalid Dataset error: ' "&amp;amp;sasin" ' does not exist';&lt;BR /&gt;
       		abort;&lt;BR /&gt;
       run;&lt;BR /&gt;
%end;&lt;BR /&gt;
&lt;BR /&gt;
%if %upcase(&amp;amp;colhead) eq NONE %then %do;&lt;BR /&gt;
        %let offset=0;&lt;BR /&gt;
%end;&lt;BR /&gt;
%else %do;&lt;BR /&gt;
        %let offset=1;&lt;BR /&gt;
%end;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
filename cmdexcel dde 'excel|system';&lt;BR /&gt;
&lt;BR /&gt;
%let fid=%sysfunc(fopen(cmdexcel,S));&lt;BR /&gt;
%if &amp;amp;fid gt 0 %then %do;&lt;BR /&gt;
    %let rc=%sysfunc(fclose(&amp;amp;fid));&lt;BR /&gt;
%end;&lt;BR /&gt;
%else %do;&lt;BR /&gt;
   %let expath='C:\Progra~1\Micros~2\Office\EXCEL.EXE';&lt;BR /&gt;
   %if %sysfunc(fileexist(&amp;amp;EXPATH)) %then %do;&lt;BR /&gt;
        x &amp;amp;expath;&lt;BR /&gt;
        data _null_;&lt;BR /&gt;
           x=sleep(5);&lt;BR /&gt;
        run;&lt;BR /&gt;
   %end;&lt;BR /&gt;
     %else %do;&lt;BR /&gt;
        %let expath='C:\Progra~1\Micros~1\Office\EXCEL.EXE';&lt;BR /&gt;
        %if %sysfunc(fileexist(&amp;amp;EXPATH)) %then %do;&lt;BR /&gt;
                x &amp;amp;expath;&lt;BR /&gt;
                data _null_;&lt;BR /&gt;
                   x=sleep(5);&lt;BR /&gt;
                run;&lt;BR /&gt;
        %end;&lt;BR /&gt;
        %else %do;&lt;BR /&gt;
        %let expath='C:\Program Files\Microsoft Office\OFFICE11';&lt;BR /&gt;
        %if %sysfunc(fileexist(&amp;amp;EXPATH)) %then %do;&lt;BR /&gt;
                x &amp;amp;expath;&lt;BR /&gt;
                data _null_;&lt;BR /&gt;
                   x=sleep(6);&lt;BR /&gt;
                run;&lt;BR /&gt;
        %end;&lt;BR /&gt;
        %else %do;&lt;BR /&gt;
        %let expath='C:\Progra~1\Msoffi~1\Office\EXCEL.EXE';&lt;BR /&gt;
        %if %sysfunc(fileexist(&amp;amp;EXPATH)) %then %do;&lt;BR /&gt;
                x &amp;amp;expath;&lt;BR /&gt;
                data _null_;&lt;BR /&gt;
                   x=sleep(10);&lt;BR /&gt;
                run;&lt;BR /&gt;
        %end;&lt;BR /&gt;
       %else %do;&lt;BR /&gt;
             data _null_;&lt;BR /&gt;
                  error 'Error: Excel could not be found';&lt;BR /&gt;
                  abort;&lt;BR /&gt;
             run;&lt;BR /&gt;
       %end;&lt;BR /&gt;
	  %end;&lt;BR /&gt;
     %end;&lt;BR /&gt;
   %end;&lt;BR /&gt;
%end;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%if &amp;amp;new eq Y %then %do;&lt;BR /&gt;
    data _null_;&lt;BR /&gt;
      file cmdexcel;&lt;BR /&gt;
      put "[new]";&lt;BR /&gt;
    run;&lt;BR /&gt;
&lt;BR /&gt;
    filename cmdexcs dde 'excel|system!selection';&lt;BR /&gt;
&lt;BR /&gt;
    data _null_;&lt;BR /&gt;
      length path $ 80;&lt;BR /&gt;
      infile cmdexcs pad dsd notab dlm='09'x;&lt;BR /&gt;
      input path $ @@;&lt;BR /&gt;
      i = index(path,']');&lt;BR /&gt;
      j = index(path,'!');&lt;BR /&gt;
      workbook = substr(path,1,i);&lt;BR /&gt;
      sheet = substr(path,i+1,j-i-1);&lt;BR /&gt;
      call symput('excelbk',trim(workbook));&lt;BR /&gt;
      call symput('excelsh',trim(sheet));&lt;BR /&gt;
    run;&lt;BR /&gt;
&lt;BR /&gt;
%end;&lt;BR /&gt;
&lt;BR /&gt;
%if &amp;amp;open eq Y %then %do;&lt;BR /&gt;
    data _null_;&lt;BR /&gt;
      file cmdexcel;&lt;BR /&gt;
      put "[open(""&amp;amp;exdirin&amp;amp;excelin"")]";&lt;BR /&gt;
    run;&lt;BR /&gt;
%end;&lt;BR /&gt;
&lt;BR /&gt;
proc contents data=&amp;amp;sasin noprint&lt;BR /&gt;
               out=conts(keep=nobs NAME label format formatl formatd type varnum);&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%if &amp;amp;SORTBY ne %then %do;&lt;BR /&gt;
    proc sort data=CONTS;&lt;BR /&gt;
      by &amp;amp;SORTBY;&lt;BR /&gt;
    run;&lt;BR /&gt;
%end;&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
  set conts end=eof;&lt;BR /&gt;
   if label eq '' then&lt;BR /&gt;
      label=NAME;&lt;BR /&gt;
   call symput('col'||left(_n_),trim(NAME));&lt;BR /&gt;
   call symput('lab'||left(_n_),trim(LABEL));&lt;BR /&gt;
&lt;BR /&gt;
   if eof then do;&lt;BR /&gt;
   call symput('columns',trim(left(_n_)));&lt;BR /&gt;
   call symput('rows',trim(left(nobs)));&lt;BR /&gt;
   end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%if %upcase(&amp;amp;colhead) ne NONE %then %do;&lt;BR /&gt;
        filename excel dde "excel|&amp;amp;exdirin&amp;amp;excelbk&amp;amp;excelsh.!r&amp;amp;st_row.c&amp;amp;st_col:r&amp;amp;st_row.c%eval(&amp;amp;columns+&amp;amp;st_col)" lrecl=2816 notab;&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
  file excel;&lt;BR /&gt;
  hextab='09'x;&lt;BR /&gt;
  %if %upcase(&amp;amp;colhead) eq NAME %then %do;&lt;BR /&gt;
    put %do i=1 %to &amp;amp;columns;&lt;BR /&gt;
    "%trim(&amp;amp;&amp;amp;col&amp;amp;i)"  hextab +(-1)&lt;BR /&gt;
    %end;&lt;BR /&gt;
    ;&lt;BR /&gt;
  %end;&lt;BR /&gt;
&lt;BR /&gt;
  %else %if %upcase(&amp;amp;colhead) eq LABEL %then %do;&lt;BR /&gt;
    put %do i=1 %to &amp;amp;columns;&lt;BR /&gt;
    "%trim(&amp;amp;&amp;amp;lab&amp;amp;i)"  hextab +(-1)&lt;BR /&gt;
    %end;&lt;BR /&gt;
    ;&lt;BR /&gt;
  %end;&lt;BR /&gt;
run;&lt;BR /&gt;
%end;&lt;BR /&gt;
&lt;BR /&gt;
filename excel dde "excel|&amp;amp;exdirin&amp;amp;excelbk&amp;amp;excelsh.!r%eval(&amp;amp;st_row+&amp;amp;offset)c&amp;amp;st_col:R%eval(&amp;amp;st_row+&amp;amp;rows+&amp;amp;offset)C%eval(&amp;amp;st_col+&amp;amp;columns)" lrecl=2816 notab;&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
  set &amp;amp;sasin;&lt;BR /&gt;
  hextab='09'x;&lt;BR /&gt;
  file excel;&lt;BR /&gt;
  put %do i=1 %to &amp;amp;columns;&lt;BR /&gt;
    %trim(&amp;amp;&amp;amp;col&amp;amp;i) +(-1) hextab +(-1)&lt;BR /&gt;
    %end;&lt;BR /&gt;
    ;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%if &amp;amp;excelout ne %then %do;&lt;BR /&gt;
    data _null_;&lt;BR /&gt;
      file cmdexcel;&lt;BR /&gt;
      put "[save.as(""&amp;amp;exdirout&amp;amp;excelout"")]";&lt;BR /&gt;
    run;&lt;BR /&gt;
%end;&lt;BR /&gt;
&lt;BR /&gt;
%if %upcase(&amp;amp;close) eq Y %then %do;&lt;BR /&gt;
    data _null_;&lt;BR /&gt;
      file cmdexcel;&lt;BR /&gt;
      put "[close]";&lt;BR /&gt;
    run;&lt;BR /&gt;
%end;&lt;BR /&gt;
%mend sas2excl;</description>
      <pubDate>Thu, 15 Oct 2009 16:09:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas2excl-macro-won-t-start-excel/m-p/75944#M16376</guid>
      <dc:creator>paulsparrow</dc:creator>
      <dc:date>2009-10-15T16:09:58Z</dc:date>
    </item>
    <item>
      <title>Re: sas2excl macro won't start excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas2excl-macro-won-t-start-excel/m-p/75945#M16377</link>
      <description>1997, it's quite some time ago?&lt;BR /&gt;
Without reading your code in detail, my guess that this could version related (SAS and/or Excel). &lt;BR /&gt;
You might want to check out some newer examples/papers. Maybe this one?&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/forum2008/259-2008.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/forum2008/259-2008.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
/Linus</description>
      <pubDate>Fri, 16 Oct 2009 12:56:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas2excl-macro-won-t-start-excel/m-p/75945#M16377</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2009-10-16T12:56:40Z</dc:date>
    </item>
  </channel>
</rss>

