BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
JJP1
Pyrite | Level 9

Hi All,

i had a batch script which calls .sas code and updates the datasets in SAS library.
So while updating the datasets it is causing issue when users open the dataset due to lock issue.
So i need to put the folder permission as 700- where SAS  datasets are getting created to avoid users not to access same via SAS app.
and after job gets completed library folder should be updated as 750 permission so that users can access and avoid lock issue.
would you please suggest any options or document links as i can't see much on google. please suggest

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

THIS WILL NOT WORK.

If a user has a dataset open before you run your job, that dataset will stay open irrespective of the access permission you set on the directory. Mind that in UNIX, the file handle of the open file works on the inode, not the directory entry.

The solution is to use a macro like I posted to remove a dataset file from the directory right before you intend to replace it; the -f option in the rm command prevents the command reacting to a file being open. I use this method successfully (for decades now!) for all our batch jobs, which means that we do not need to interrupt end-user access when we update our SAS tables.

The only disadvantage is that you cannot use proc append (which would fail anyway), but need to do an eventual append in WORK or another place that is not available for other users.

View solution in original post

14 REPLIES 14
Patrick
Opal | Level 21

If data volumes don't forbid then eventually maintain two data sets in two different libraries/folders. One is your source of truth which only your batch user can access. Once the batch process has finished copy the whole sas7bdat file to a location where users can access the data.

 

The cp command will simply overwrite (replace) the destination file if it already exists and even if it's currently opened by some other process (the SAS session of your user). But the way Linux/Unix does this the other process using the old version should still continue to work and should still have access to the old version. The old file gets only fully deleted once no process has it open anymore. Any new process will pick-up the new version of your file/data.

I believe that should pretty much give you what you need.

JJP1
Pyrite | Level 9

yes @Patrick .but batch unix job gets failed saying that dataset lock issue. so could you please help where i can put the folder permission to 700 and i know it's in .sas code. but not getting clear idea. thanks. any advise please.

Oligolas
Barite | Level 11

Hi,

I can not help you with Linux. But maybe if consensus isn't feasible in your team, couldn't you create the files in a temporary Folder and robocopy the whole bunch once they aren't locked anymore?

________________________

- Cheers -

Patrick
Opal | Level 21

@Oligolas 

One of the good things using Unix/Linux: No problem to replace a locked file. Explanations how Windows and Unix/Linux are different in this regard here.

JJP1
Pyrite | Level 9

hi all. can anyone help how to set the folder permission for folder in below SAS code.

before running the job the folder should be 700 and after it gets completed it should be 750

 

%macro job;

%let date = %substr(&sysdate.,1,2);
%put value of date is &date.;
%if %eval(&date = 01) %then %do;
%global job;
%let job=job;
%trace(************************************************************);
%trace(NOTE: Starting job);
%trace(NOTE: 1st day of the month);
%trace(************************************************************);
%end;
%else %do;
%auto(jobname=job,
jobpath=&path./job
                    );
					

%end;

%mend;

%job;
Kurt_Bremser
Super User

Remove the dataset before writing it:

%macro del_dataset(library,dsname);
%local physname;
%let physname=%sysfunc(pathname(&library.))/%sysfunc(lowcase(&dsname.)).sas7bdat;
X "rm -f &physname.";
%mend;

This will work as long as you have write permission for the directory (which you need to have anyway).

Kurt_Bremser
Super User

Changing the permission of the directory to which your libref points won't help anyway. If a user has a dataset open at this point, it will stay opened, as the permissions are evaluated only when the file is opened. OTOH, all other datasets in the library would not be accessible for further use, and the library assignments (which you probably have either in autoexec or in the metadata) will all fail.

JJP1
Pyrite | Level 9

Yes @Kurt_Bremser , i don't want all other datasets present in that library should be accessible to the users please.

 

So you mean that i need to write code to remove all physical datasets will be more efficient than the setting folder permission please ?

 

Sorry if it does not make sense. if i use the folder permission as 700 then all datasets in that library/folder  for users wont be available right so the job will not fail. would you please suggest how to achieve this.

Kurt_Bremser
Super User

THIS WILL NOT WORK.

If a user has a dataset open before you run your job, that dataset will stay open irrespective of the access permission you set on the directory. Mind that in UNIX, the file handle of the open file works on the inode, not the directory entry.

The solution is to use a macro like I posted to remove a dataset file from the directory right before you intend to replace it; the -f option in the rm command prevents the command reacting to a file being open. I use this method successfully (for decades now!) for all our batch jobs, which means that we do not need to interrupt end-user access when we update our SAS tables.

The only disadvantage is that you cannot use proc append (which would fail anyway), but need to do an eventual append in WORK or another place that is not available for other users.

JJP1
Pyrite | Level 9

Thanks you so much @Kurt_Bremser and i will be working on this as you suggested please.thanks.

Iam including  the macro .sas code that is  called by .sh script is it fine right ?

 

Just now found out that one of the section of code is using proc append option for one of the dataset please.

 

Kurt_Bremser
Super User

First test the code before you put it in production use.

My macro code is actually a lot larger, as it is able to recognize views from datasets (as the extension needs to change to .sas7bvew), has safeguards in case we have a problem further up in the code (it only works if both &SYSCC and &SYSRC are zero), and submits the external command in a data _null_ step with PIPE so any problem there is viewable in the log.

Patrick
Opal | Level 21

@Kurt_Bremser 

Where did you post this macro?

And just curious: Wouldn't cp also work?

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 14 replies
  • 1654 views
  • 3 likes
  • 4 in conversation