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

发布于 2024-07-30 00:28:48 字数 91 浏览 6 评论 0原文

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

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

Ever had a problem with a SAS session, but been unable to close the session due to having critical files in your remote work library (RWORK)??

I certainly have! So how do you access that library from another (new) session?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

烦人精 2024-08-06 00:28:48

这是我编写的一个宏,用于将多个 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 ;

Here's a macro I wrote to assign a multiple libref to all remote work directories owned by you :

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 ;
遇到 2024-08-06 00:28:48

不确定提出一个你知道答案的问题的道德规范,但希望其他人会发现这很有用!

%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 被擦除)并且第二个会话需要登录到同一服务器...

not sure of the ethics of asking a question you know the answer to, but hopefully others will find this useful!

%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;

This will put the code you need in the log. The bit you may need to change is the server= option - this should be the name of the environment you have logged onto (not sure how to reference this programmatically - does anyone else know?)

Obviously the original session needs to remain open (to prevent RWORK from being wiped) and the second session needs to be logged onto the same server...

后知后觉 2024-08-06 00:28:48

回应 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;

response to Chris J's response - missing macro..

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文