0
votes

BACKGROUND

I have a script that runs every month creating the dataset to be used by my team. The script generates datasets in my personal UNIX directory, I then run sanity checks and copy the dataset to a "public" directory where my team can access it. The script is stable so there is no need to run sanity checks anymore.

WHAT I WANT TO DO

  • Extract the last modified date from previous version of the dataset from the public folder (Working fine)
  • Upend the previous dataset name with modified date (facing issues)
  • Move/copy the newly created dataset to public folder (Working fine)

PROBLEM STATEMENT

I am getting following error while attempting to change the dataset name

ERROR: You cannot rename COSTDATA.EMPL_CHAIN.DATA to COSTDATA.EMPL_CHAIN_19SEP18.DATA because COSTDATA.EMPL_CHAIN.DATA is in use by you in resource environment IOM ROOT COMP ENV.

CODE USED

%let dsid2=%sysfunc(open(costdata.empl_chain));
%put ********&dsid2;
%let modte2=%sysfunc(attrn(&dsid2,modte),datetime7.);
%put &modte2;
%let rc=%sysfunc(close(&dsid2));
%put RC Value is &rc;

proc datasets library=costdata;
change empl_chain=empl_chain_&modte2;
run;

SAS LOG

29         %let dsid2=%sysfunc(open(costdata.empl_chain));
30         %put ********&dsid2;
********2
31         %let modte2=%sysfunc(attrn(&dsid2,modte),datetime7.);
32         %put &modte2;
19SEP18
33         %let rc=%sysfunc(close(&dsid2));
34         %put RC Value is &rc;
RC Value is 0
35         


36         proc datasets library=costdata;
37         change empl_chain=empl_chain_&modte2;
38         run;

NOTE: Changing the name COSTDATA.EMPL_CHAIN to COSTDATA.EMPL_CHAIN_19SEP18 (memtype=DATA).
ERROR: You cannot rename COSTDATA.EMPL_CHAIN.DATA to COSTDATA.EMPL_CHAIN_19SEP18.DATA because COSTDATA.EMPL_CHAIN.DATA is in use by you in resource environment IOM ROOT COMP ENV.
39

Other helpful information:

I am trying to do the similar operation to multiple datasets. The rename piece works fine for the first dataset if the SAS EG session is new. It predictably fails for second dataset onward. In EG, Tools > Options > Data > Data General... the 'Automatically open data when added to project' checkbox is Unchecked as suggested by SAS.

I am also aware of other simple tricks such as declaring a new dataset with correct name in a new data step or using 'exchange' function in proc dataset. I would like to know however, if there is any solution to the above error.

3
Do you get any errors earlier? I do when I try and run your code.Reeza

3 Answers

0
votes

An alternative approach is to get the modified date another way.

%let dset = CLASS;

proc sql noprint;
select put(datepart(modate), yymmddn8.) into :modte
from sashelp.vtable
where libname='WORK' and memname="&dset.";
quit;

%put &modte.;


proc datasets library=work;
change &dset. = &dset._&modte.;
run;
0
votes

https://communities.sas.com/t5/SAS-Programming/sysfunc-open-causes-table-to-be-locked-if-error-occurs/td-p/57601 discusses a series of causes

Including:

  • LOCKed members
  • Held open by client (EG) settings
  • Opened with errors and no checks on open function

What is the dsid returned from the second %sysfunc(open attempt and the %sysfunc(sysmsg()) ?

Can you ssh into your Unix host and issue a command to list lockers ? Commands such as flock lslock, lslk, lsof

0
votes

Well, I'm lost. Your code runs fine for me, from EG 7.15 talking to SAS 9.4M4 session on linux. Below is an example, using WORK library. Can you use see if this reproduces the problem in your environment, and if not, can you post full code that does reproduce the problem using data created from SASHELP datasets?

From the log you shared, it looks like all the return codes are good, so the SAS code shouldn't be locking the file. Once you have a reproducible example, maybe try batch submitting it on the server (assuming you can access via ssh), just to see if EG is somehow causing the lock.

data class ;
  set sashelp.class ;
run ;

data shoes ;
  set sashelp.shoes ;
run ;

%let dsid2=%sysfunc(open(work.class));
%put ********&dsid2;
%let modte2=%sysfunc(attrn(&dsid2,modte),datetime7.);
%put &modte2;
%let rc=%sysfunc(close(&dsid2));
%put RC Value is &rc;

proc datasets library=work;
change class=class_&modte2;
run;

%let dsid2=%sysfunc(open(work.shoes));
%put ********&dsid2;
%let modte2=%sysfunc(attrn(&dsid2,modte),datetime7.);
%put &modte2;
%let rc=%sysfunc(close(&dsid2));
%put RC Value is &rc;

proc datasets library=work;
change shoes=shoes_&modte2;
run;