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
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.
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.
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.
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 -
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;
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).
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.
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.
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.
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.
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.
cp should also work, but you will also need to use the -f option.
I will post a (hopefully) generic macro as a library article soon.
I just posted an article containing an expanded version of the macro that does most of the work automatically:
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.