title: Running SAS code from Excel
body: <p>I have multiple SAS codes that I run monthly. I would like to have an excel spreadsheet that contains all of the code and from which each piece of code can be run.</p>
  
  <p>Firstly, is there just a simple way of doing this? I assume it would just call the code location and run it from there? Are there particular references that I need?</p>
  
  <p>I found this piece of code and have been trying to use it, but I think something is wrong as it is telling me the license is expired but the code works when I run it in excel.</p>
  
  <p>Here is the VBA code:</p>
  
  <pre><code>Sub RunSAS()
  '--&gt; Verify Run Request (Exit If Cancelled)
  a = MsgBox("Run " &amp; ActiveCell.Value &amp; "?", vbOKCancel, "Run SAS Program Confirmation")
  If a = vbCancel Then
  Exit Sub
  End If
  '--&gt; Run SAS Program
  Z = Shell("C:\Program Files\SAS\x86\SASFoundation\9.3\sas.exe -initstmt '%include """ &amp;     ActiveCell.Value &amp; """ / source2; run;'", vbNormalFocus)
  
  '--&gt; If Requested, Insert Run Time/Date In FIFO Order
  ' ('Run History' Must Appear In First Row Of Column To Right Of Program Name)
  If UCase$(Trim(Cells(1, ActiveCell.Column + 1).Value)) = "RUN HISTORY" Then Cells   (ActiveCell.Row, ActiveCell.Column + 1).Select
  Selection.Insert Shift:=xlToRightCells(ActiveCell.Row, ActiveCell.Column + 1).Select
  Selection.Copy Cells(ActiveCell.Row, ActiveCell.Column - 1).Select
  Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
  False, Transpose:=False
  Selection.Value = Date &amp; " " &amp; Time()
  Cells(ActiveCell.Row, ActiveCell.Column - 1).Select
  Application.CutCopyMode = False
  End If
  
  End Sub
  </code></pre>
  
  <p>The SAS code I am trying to execute is very simple and just attempts to send myself an email.</p>
  
  <pre><code>%INC 'H:\sasconnect\idwapid.inc';
  OPTIONS COMAMID=tcp;
  
  FILENAME RLINK '\\int\groupdata\IDW\sasscript\SAS93\sasap6\prod\Res_sasapv93_prod.scr';
  
  %let host=idwap1 17554;
  %let server=host;
  SIGNON remote=&amp;server;
  
  RSUBMIT;
  
  *** send email ***;
  FILENAME eml2 email TO= ("a.m@company.com.au") SUBJECT="Test";   
  DATA _NULL_;
    FILE eml2;            
    PUT "Email 3";
  RUN;
  
  endrsubmit;
  signoff;
  </code></pre>
  
  <p>Any help would be appreciated.</p>