2013-11-02 29 views
1

我想弄清楚如何使用SAS namedpipes在SAS進程中交換數據。下面是一個簡單的例子:使用namedpipes傳輸ods輸出和數據集

服務器

FILENAME stdout namepipe '\\.\pipe\Sas\PipeOut' server eofconnect retry=15 block; 
FILENAME DIRLIST pipe 'dir "C:\atemp"'; 
data dirlist ; 
    length buffer $256; 
    infile dirlist length=reclen; 
    input buffer $varying256. reclen; 
    *file stdout; 
    *put buffer; 
ods listing file=stdout; 
proc print data=dirlist; 
run; 

客戶

FILENAME stdin namepipe '\\.\pipe\Sas\PipeOut' client eofconnect retry=15 block; 
data d1; 
    length buffer $ 256; 
    infile stdin length=reclen; 
    input buffer $varying256. reclen; 
    put buffer; 
run; 

如果服務器代碼我去掉了該文件,並把語句,並刪除ODS和PROC打印,一切都非常按預期工作。現在的代碼產生了我沒有想到的結果。我運行服務器代碼,然後啓動客戶端代碼。客戶端代碼運行,但讀取零觀察值,如果我然後重新運行客戶端代碼(在服務器超時之前),它將讀取60條左右預期的行,然後掛起(從不終止)。我最好的猜測是,ods列表聲明關閉文件,然後重新打開它(並且從不關閉它?)。有沒有人知道發生了什麼,以及如何在第一次執行時在客戶端獲取ods輸出,而沒有掛起?

我想要做的其他事情是將服務器上的數據集輸出到管道並將其用作客戶端中的數據集引用。通常這是使用庫引用完成的,我不知道我是否能夠或如何使管道文件引用看起來像庫引用。希望最後一部分有意義。

回答

1

首先,要修復掛起,您需要關閉服務器上的管道。

ods listing close; 

我無法解釋必須運行客戶端兩次。

將代碼更改爲此作品。

服務器

FILENAME stdout namepipe '\\.\pipe\Sas\PipeOut' server eofconnect retry=15 block; 
FILENAME DIRLIST pipe 'dir "C:\temp"'; 
data dirlist ; 
    length buffer $256; 
    infile dirlist length=reclen; 
    input buffer $varying256. reclen; 
    *file stdout; 
    *put buffer; 
run; 

ods listing file=stdout; 

proc print data=dirlist; 
run; 

ods listing close; 

客戶

FILENAME stdin namepipe '\\.\pipe\Sas\PipeOut' client retry=15 ; 

/*Extra read to clear whatever weirdness ODS does.*/ 
data _null_; 
infile stdin; 
input; 
run; 

data d1; 
    length buffer $ 256; 
    infile stdin length=reclen; 
    input buffer $varying256. reclen; 
    put buffer; 
run; 

我懷疑所消耗臭氧層物質的語句做一些事情來創建一個文件。這是第一次寫入管道。下一次寫入管道是一種修改。這就是爲什麼你必須從中讀取兩次。

關於共享數據的第二個問題。我不確定你可以用二進制形式管理數據集。你可以把它寫成類似CSV的東西,並將它讀入客戶端的數據集中。

服務器

FILENAME stdout namepipe '\\.\pipe\Sas\PipeOut' server eofconnect retry=15 block; 

proc export data=sashelp.class outfile=stdout dbms=csv replace; 
run; 

filename stdout clear; 

在您需要將結果寫入到一個臨時文件的客戶端。 Proc IMPORT需要隨機訪問,並且命名管道不能隨機訪問。

FILENAME stdin namepipe '\\.\pipe\Sas\PipeOut' client retry=15 ; 

filename x temp; 
data _null_; 
    length buffer $4000.; 
    infile stdin length=reclen; 
    file x; 
    input; 
    buffer = _infile_; 
    put buffer; 
run; 

proc import file=x out=class dbms=csv replace; 
run; 

filename x clear; 
+0

非常感謝您的回答。 ods close和額外的輸入步驟處理讀取和掛起問題。我擔心可能無法執行二進制數據集傳輸。我打算把問題留給希望可能成爲一種方式的日子,因爲我想避免寫一個文件。 – Dweeberly

+0

我打算將其標記爲答案。我可能無法以這種方式傳遞(二進制)數據集。其他信息是現貨,並像魅力一樣工作,再次感謝 – Dweeberly