国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

建立同SAS交互的開發(fā)式VB客戶端

2024-07-21 02:20:38
字體:
供稿:網(wǎng)友
簡介
程序員常問哪一種語言能訪問sas,那就是用sas的it機制,它容許開發(fā)式客戶訪問sas,程序員能用不同的語言快速的建立同sas交互的強壯的應用,此文主要介紹大家如何用vb同sas交互
讀前需知
該文假設(shè)讀者對vb/com/sas知識有一定的了解
sas it的組件
sas it是一個中間件,是為用戶提供訪問sas和呈現(xiàn)數(shù)據(jù)的接口,它包含下面功能
1、ldap(輕量級目錄訪問協(xié)議)目錄集成
ldap是一個分布式存儲數(shù)據(jù)的工業(yè)標準,程序員可以使用微軟的adsi(動態(tài)目錄服務接口)訪問ldap目錄,你可以把ldap認為一個可以通過tcp/ip訪問的數(shù)據(jù)庫,通常,一個組織會有一個單一的ldap 服務器,并被該組織的所有機器共享
2、發(fā)布/訂閱
這種積極的信息傳送機制能使你制造sas輸出(發(fā)布者)到那些對這些輸出感興趣的人(訂閱者)
這種機制是由iom(整合對象模型)接口、sas語言調(diào)用語法和ldap對象組成并協(xié)同工作的
3、消息隊列
sas可以把輸出信息輸出到消息隊列,這樣客戶端沒有必要等待sas執(zhí)行完成
關(guān)于消息隊列的詳細用法情參考:
http://www.sas.com/rnd/itech/doc/messageq/index.htm
4、iom(綜合對象模型)
iom是一組com對象的集合,其中大多數(shù)通常被vb使用
sas it比以前版本提供的ole接口的優(yōu)勢
it是以前ole的延伸,下面比較一下三種主要的不同
1、it提供了多層次的接口,而ole只提供了單一的接口
2、it是跨平臺(sas所能支持的平臺,如:win/unix/os等)的,vb應用能通過遠端調(diào)用it對象,而ole只能運行于win平臺
3、it對象容許sas 程序異步運行,而ole不能
注:it對象的根對象為“sas.workspace” ,其對應了ole的 “sas.application”對象
vb程序員的it工具
包含iom、sas workspace manager、iom數(shù)據(jù)提供者、iom bridge for com、scripto
iom
客戶端可以通過多種連接方式連接到iom 服務器,如corba/jdbc/com/omg等,而沒有必要附加代碼到客戶端
iom是一個對象模型,因為它暴露了一組對象供用戶使用
這些對象可以用來實現(xiàn)2個目標:提交代碼給sas和獲得sas的輸出
在所以iom對象中,數(shù)組被廣泛的使用,所以所有請求是被同時返回的
所需注意的是:如果沒有sas it產(chǎn)品的授權(quán),iom接口只能被本地com使用,如過有授權(quán),則可以通過網(wǎng)絡(luò)訪問遠端的iom接口
iom對象層次上的根對象是workspace,每個這樣的對象都有它自己的work庫
workspace對象提供了下面可用的對象
dataservice對象:返回一個操作sas庫的接口,它同時也提供了一個讀寫sas數(shù)據(jù)的接口,但vb程序員不能直接使用,只能通過sas 數(shù)據(jù)提供者間接調(diào)用
fileservice對象:返回一個讀寫sas服務器文件和文件引用的接口
getapplication對象:返回一個有sas/af建立的自定義接口
languageservice 對象:返回一個提交sas代碼并獲得輸出的接口
iom使用例子
假設(shè)下面代碼已經(jīng)被執(zhí)行
dim obwsmgr as new _
sasworkspacemanager.workspacemanager
dim obsas as sas.workspace
dim xmlinfo as string
' this creates a sas server running on the
' local machine
set obsas = obwsmgr.workspaces.createworkspacebyserver ("", visibilitynone, nothing, "", "", xmlinfo)
例子1:提交代碼
有2種方式可以提交代碼到sas server
方式1:使用languageservice
obsas.languageservice.submit _
"data a; do x= 1 to 10; y=x*x*x;" & _
"output;end;run;"
msgbox obsas.languageservice.flushlog(100000)
方式2:使用 storedprocessservice
這種方式請求sas文件存放在已知的目錄中,且能過通過宏的方式傳參數(shù)給文件,而在sas文件中要想接收參數(shù)信息,需使用這樣的語法:
*processbody;
它會自動把傳入的參數(shù)轉(zhuǎn)換為宏

如有多個參數(shù),在傳入的時候用【空格】分隔
例如:
' 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文件內(nèi)容如下:
%let looptimes=3;
*processbody;
data a;
do x= 1 to &looptimes;
y=x*x*x;
output;
end;
run;
例子2:執(zhí)行代碼
async屬性:如果為false,則為同步執(zhí)行,否,為異步執(zhí)行,可以通過事件獲得是否已成功執(zhí)行完成
如下定義一個錯誤發(fā)生事件:
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 能夠提供二進制數(shù)據(jù)訪問給用戶
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"
其實在單機環(huán)境中就沒有必要這樣做了 :)

使用resultpackageservice也可獲得輸出,它可以通過workspace.utilities.resultpackageservice引用
你可以使用resultpackageservice提供的接口建立resultpackage,當然也可以通過sas語言的call語法
一個resultpackage可以是任意的sas輸出,如文件,數(shù)據(jù)集,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"
關(guān)于sas workspace manager
它是一個完成下面功能的activex控件
1、它同sas建立連接,并返回工作空間
2、它提供了一個池保證每個工作空間在web環(huán)境中是安全的
3、自動保持同sas的連接
你可以使用以下2種方式建立同sas的連接
非被管理模式(所有連接信息保留在客戶端)
被管理模式 (所以連接信息保留在文件或者ldap中)
這些連接信息包含 連接到哪臺機器、用什么協(xié)議、使用什么端口或者服務名字、用戶名、用戶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參數(shù)返回服務器實際上使用的值
關(guān)于iom data provider
iom data provider是一個使用iom dataservice讀寫數(shù)據(jù)的ole db的數(shù)據(jù)提供者
你可以使用ado讀寫數(shù)據(jù)
例如:
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
關(guān)于iom com橋
當sas運行window上時,你可以使用com或者dcom,然而當sas運行于unix或者os上時,則不能使用com技術(shù)調(diào)用sas,sas提供了iom com橋,它一方便呈現(xiàn)com接口給客戶端,一方面使用tcp/ip跟sas進行通信

關(guān)于scripto
scripto 是一個用于腳本應用的acitvex對象,其使用解決了腳本同sas組件對象交互使用的幾個限制,如vbscript只能返回一個單一參數(shù);vbscript請求所有變量為variant,故數(shù)祖也被處理為variant,scripto就解決這2個問題,容許返回多個參數(shù),可以使用數(shù)組進行傳輸
' 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)

關(guān)于it客戶端
你需要在客戶端安裝和注冊幾個文件
it客戶端的必要文件是自動安裝執(zhí)行的,通過調(diào)用inttech.exe,其會安裝必要的文件通過網(wǎng)絡(luò)

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 康保县| 东平县| 信宜市| 长武县| 信丰县| 库尔勒市| 上思县| 吴川市| 永德县| 蚌埠市| 吉水县| 文登市| 丹江口市| 台南县| 博乐市| 民丰县| 常山县| 鹰潭市| 阳城县| 洱源县| 杭州市| 梓潼县| 东明县| 镇康县| 永兴县| 浙江省| 井陉县| 巴彦淖尔市| 望都县| 乡城县| 宁津县| 嘉兴市| 望江县| 宁化县| 浦城县| 仁化县| 新竹县| 三门县| 清苑县| 安福县| 寿宁县|