从另一个会话引用远程SAS工作库

时间:2009-07-29 10:38:02

标签: sas sas-macro

SAS会话遇到问题,但由于远程工作库(RWORK)中有关键文件而无法关闭会话?

我当然有!那么如何从另一个(新)会话访问该库?

3 个答案:

答案 0 :(得分:2)

不确定提问你知道答案的道德,但希望其他人会觉得这很有用!

%macro serverpath;
%put NOTE:; %put NOTE-; %put NOTE-; 
%put NOTE- libname OldWork "%sysfunc(pathname(RWORK))" server= remote %str(;);
%put NOTE- rsubmit%str(;);
%put NOTE- libname OldWork "%sysfunc(pathname(RWORK))"%str(;);
%mend; %serverpath;

这会将您需要的代码放在日志中。您可能需要更改的位是server =选项 - 这应该是您已登录的环境的名称(不确定如何以编程方式引用它 - 其他人是否知道?)

显然原始会话需要保持打开状态(防止RWORK被擦除),第二个会话需要登录到同一台服务器上......

答案 1 :(得分:2)

这是我编写的一个宏,用于为您拥有的所有远程工作目录分配多个libref:

rsubmit ;

%MACRO DOUBLELIB(USER=&SYSUSERID,LIB=double) / des="Assign libname of double for multiple SAS sessions for the same user";

 options nosymbolgen nomprint ;

 %LET WRK     = %SYSFUNC(pathname(work)) ;
 %LET WRKDIR  = %SYSFUNC(scan(&WRK,-1,/)) ;
 %LET SASTEMP = %SYSFUNC(tranwrd(&WRK,&WRKDIR,)) ;

 filename mywork pipe "ls -ls &SASTEMP" ;
 data zwork ;
   infile mywork lrecl=512 recfm=v pad ;
   input @1 char $512. ;
   if index(upcase(char),upcase("&USER")) and ^index(char,scan("&WRK",-1,'/')) and index(char,'SAS_work');
   path = scan(char,-1,' ') ;
   n + 1 ;
   call symput('PATH'||compress(n),"&SASTEMP"||strip(path)) ;
   call symput('PATHN',compress(n)) ;
 run ;

 %NOBS(zwork) ;
 %IF &NOBS > 0 %THEN %DO ;
   libname &LIB (
     %DO I = 1 %TO &PATHN ;
       "&&PATH&I"
     %END ;
   ) access=readonly ;
 %END ;
 options symbolgen mprint ;
%MEND DOUBLELIB;

%DOUBLELIB(LIB=dblwork) ;

endrsubmit ;

/* Assign local libref to new remote dblwork libref */
libname rdouble slibref=dblwork server=myserver ;

答案 2 :(得分:2)

回应Chris J的回应 - 遗失了宏..

rsubmit ;
%macro nobs(dsn);
%local dsnid rc;
%global nobs;
%let nobs=.;
%* open the data set of interest ;
%let dsnid=%sysfunc(open(&dsn));
%* If the open was successful get the nobs and CLOSE &dsn ;
%if &dsnid %then %do;
    %let nobs=%sysfunc(attrn(&dsnid,nlobs)); 
    %let rc =%sysfunc(close(&dsnid));
%end; %else %do; 
    %put WARNING:  Unable to open &dsn - %sysfunc(sysmsg());
    %let nobs=0;
%end;  %mend nobs;
endrsubmit;