vba 从 Excel 运行 SAS 代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17397666/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Running SAS code from Excel
提问by amymon87
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.
我有多个每月运行的 SAS 代码。我想要一个包含所有代码的 excel 电子表格,并且可以从中运行每段代码。
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?
首先,有没有一种简单的方法可以做到这一点?我认为它只会调用代码位置并从那里运行它?是否有我需要的特定参考资料?
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.
我找到了这段代码并一直在尝试使用它,但我认为有些问题,因为它告诉我许可证已过期,但是当我在 excel 中运行它时代码可以工作。
Here is the VBA code:
这是VBA代码:
Sub RunSAS()
'--> Verify Run Request (Exit If Cancelled)
a = MsgBox("Run " & ActiveCell.Value & "?", vbOKCancel, "Run SAS Program Confirmation")
If a = vbCancel Then
Exit Sub
End If
'--> Run SAS Program
Z = Shell("C:\Program Files\SAS\x86\SASFoundation.3\sas.exe -initstmt '%include """ & ActiveCell.Value & """ / source2; run;'", vbNormalFocus)
'--> 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 & " " & Time()
Cells(ActiveCell.Row, ActiveCell.Column - 1).Select
Application.CutCopyMode = False
End If
End Sub
The SAS code I am trying to execute is very simple and just attempts to send myself an email.
我试图执行的 SAS 代码非常简单,只是尝试给自己发送一封电子邮件。
%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=&server;
RSUBMIT;
*** send email ***;
FILENAME eml2 email TO= ("[email protected]") SUBJECT="Test";
DATA _NULL_;
FILE eml2;
PUT "Email 3";
RUN;
endrsubmit;
signoff;
Any help would be appreciated.
任何帮助,将不胜感激。
回答by Grem
Have you heard of the "SAS? Add-In for Microsoft Office" product? details available at http://support.sas.com/software/products/addin/
您听说过“SAS?Microsoft Office 插件”产品吗?详情请见http://support.sas.com/software/products/addin/