如有多个参数,在传入的时候用【空格】分隔
例如:
run the sas program at c:\temp\looper.sas
dim obstoredprocessservice as _
sas.storedprocessservice
set obstoredprocessservice = _
obsas.languageservice.storedprocessservice
obstoredprocessservice.repository = _
"file:c:\temp"
obstoredprocessservice.execute "looper", _
"looptimes=10"
msgbox obsas.languageservice.flushlog(100000)
looper.sas文件内容如下:
%let looptimes=3;
*processbody;
data a;
do x= 1 to &looptimes;
y=x*x*x;
output;
end;
run;
例子2:执行代码
async属性:如果为false,则为同步执行,否,为异步执行,可以通过事件获得是否已成功执行完成
如下定义一个错误发生事件:
public withevents obsaslanguage as _ sas.languageservice
to enable events, you must associate the
obsaslanguage
interface with the same languageservice
interface used to make calls.
set oblanguage = obsas.languageservice
oblanguage.submit "this is an error;run;"
private sub oblanguage_steperror()
an error has occurred. dump the log
debug.print oblanguage.flushlog(100000)
end sub
例子3:获得输出
sas会输出多种类型的信息供用户使用,如下
iom data provider 能够提供二进制数据访问给用户
languageservice的flushlist flushlistlines方法可以获得sas的窗口输出
如果想获得ods输出,可以通过文件引用的方式,sas提供的fileservice提供这样的服务
下面演示如何通用fileservice方式获得输出
dim obfileref as sas.fileref
dim obtextstream as sas.textstream
dim obfilesystem as new scripting.filesystemobject
dim obfile as scripting.textstream
set obfile = obfilesystem.createtextfile ("c:\temp\sasoutput.htm",
true)
obsas.languageservice.submit "filename fref temp;" & "ods html
body=fref;" & "proc corr data=sashelp.class;" & "run;" & "ods html
close;"
set obfileref = obsas.fileservice.usefileref("fref")
set obtextstream = obfileref.opentextstream (streamopenmodeforreading,
10000)
sodsoutput = obtextstream.read(100000)
while (len(sodsoutput) > 0)
do something with the read text here
obfile.write sodsoutput
sodsoutput = obtextstream.read(100000)
wend
webbrowser1.navigate "c:\temp\sasoutput.htm"
其实在单机环境中就没有必要这样做了 :)
使用resultpackageservice也可获得输出,它可以通过
workspace.utilities.resultpackageservice引用
你可以使用resultpackageservice提供的接口建立resultpackage,当然也可以通过sas语言的call语法
一个resultpackage可以是任意的sas输出,如文件,数据集,ods输出、图片等
下面这个例子显示如何建立一个 resultpackage
%macro checkrc(rc);
if rc ne 0 then do;
msg = sysmsg();
put msg;
abort;
end;
%mend;
data _null_;
call package_begin(pid, desc, nameval, rc);
%checkrc(rc);
call insert_file(pid, fileref:fref,
"text", "text/html", "some ods output",
, rc);
%checkrc(rc);
/* nothing in the package actually gets
* written out until we call publish.
* so, if you modify any filerefs after
* calling insert but before calling
* this, then you will get the
* modified fileref.*/
call package_publish(pid, "to_archive", rc,
"archive_path, archive_name", "c:\temp",
"archive");
%checkrc(rc);
/* you could call package_publish as many
* times as you want for any given package,
* as long as you
* do so before calling package_end. */
call package_end(pid, rc);
%checkrc(rc);
run;
下面显示如何读这个 resultpackage
dim props() as string
dim obresultpackage as sas.resultpackage
dim obfileentry as sas.resultpackagefileentry
dim obrps as sas.resultpackageservice
set obrps = obsas.utilities.resultpackageservice
set obresultpackage = obrps.browseresultpackage( "archive", "c:\temp
\archive.spk", props)
set obfileentry = obresultpackage.getentry(0)
set obtextstream = obfileentry.open (streamopenmodeforreading,
100000)
sodsoutput = obtextstream.read(100000)
while (len(sodsoutput) > 0)
do something with the read text here
obfile.write sodsoutput
sodsoutput = obtextstream.read(100000)
wend
webbrowser1.navigate "c:\temp\sasoutput.htm"
关于sas workspace manager
它是一个完成下面功能的activex控件
1、它同sas建立连接,并返回工作空间
2、它提供了一个池保证每个工作空间在web环境中是安全的
3、自动保持同sas的连接
你可以使用以下2种方式建立同sas的连接
非被管理模式(所有连接信息保留在客户端)
被管理模式 (所以连接信息保留在文件或者ldap中)
这些连接信息包含 连接到哪台机器、用什么协议、使用什么端口或者服务名字、用户名、用户id等,同时dcom或者iom支持加密的session
例子1:建立连接,非被管理模式
dim obwsmgr as new _
sasworkspacemanager.workspacemanager
dim obsas as sas.workspace
dim xmlinfo as string
dim observer as new _
sasworkspacemanager.serverdef
observer.machinednsname = "remote.sas.com"
set obsas = _
obwsmgr.workspaces.createworkspacebyserver _
("", visibilitynone, observer, "", "", _
xmlinfo)
xmlinfo参数返回服务器实际上使用的值
关于iom data provider
iom data provider是一个使用iom dataservice读写数据的ole db的数据提供者
你可以使用ado读写数据
例如:
set obsas = _
obwsmgr.workspaces.createworkspacebyserver _
("",visibilityprocess,observer,"","", _
xmlinfo)
dim obconnection as new adodb.connection
obconnection.open _
"provider=sas.iomprovider.1;" & _
"sas workspace id=" & obsas.uniqueidentifier
dim obrs as new adodb.recordset
obrs.open "sashelp.class", obconnection, _
adopendynamic, adlockreadonly, _
adcmdtabledirect
set mschart1.datasource = obrs
关于iom com桥
当sas运行window上时,你可以使用com或者dcom,然而当sas运行于unix或者os上时,则不能使用com技术调用sas,sas提供
了iom com桥,它一方便呈现com接口给客户端,一方面使用tcp/ip跟sas进行通信
关于scripto
scripto 是一个用于脚本应用的acitvex对象,其使用解决了脚本同sas组件对象交互使用的几个限制,如vbscript只能返回一个单一
参数;vbscript请求所有变量为variant,故数祖也被处理为variant,scripto就解决这2个问题,容许返回多个参数,可以使用
数组进行传输
scripto will do 2 things:
1) it will convert the 3 returned arrays to arrays of variants instead
of arrays of
longs so vbscript can handle them
2) it allows more than 1 return parameter
set obsas = createobject("sas.workspace")
set obscripto = _
createobject("sasscripto.scripto")
obsas.languageservice.submit _
"proc options;run;"
obscripto.setinterface obsas.languageservice
obsas.languageservice.flushloglines 1000, carriagecontrols, linetypes,
loglines
dim flushloglinesparams(3)
flushloglinesparams(3) = 1000
obscripto.invokemethod "flushloglines", _
flushloglinesparams
flushloglinesparams(0) now has loglines
flushloglinesparams(1) has linetypes
flushloglinesparams(2) has carriagectrls
this prints the first line
wscript.echo flushloglinesparams(0)(0)
关于it客户端
你需要在客户端安装和注册几个文件
it客户端的必要文件是自动安装执行的,通过调用inttech.exe,其会安装必要的文件通过网络
文章整理:西部数码 http://www.west263.com