Question

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?

Was it helpful?

Solution

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 ;

OTHER TIPS

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...

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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top