I need to create several external files and establish their permissions as u=rwx, g=rwx, and o=r-x. I can accomplish this easily if an output file isn't created using "FILEVAR". Can I not do this using "FILEVAR"? Please see the attached code. What is the proper way?
Jackie O.
Note that since you are turning on the group write bit on the files you might will also want to make sure to turn it on for the folder.
You might also want to set the group sticky bit on the folder when it is created. That way all files created in the folder will be in the same group.
mkdir -p myfolder
chmod g+s,g+w myfolder
cd myfolder
umask 002
sas myprogram
Here are some resources that you might find helpful http://support.sas.com/techsup/technote/ts581.pdf and https://support.sas.com/resources/papers/proceedings/proceedings/sugi27/p082-27.pdf
Depending on how the SAS session is started (shell command? using a Workspace server in SAS EG or SAS Studio?), you may be able to influence the default permissions by setting the umask -- see this note.
Oh, but I see your question is about FILEVAR -- I think the answer is No, it doesn't work that way with PERMISSION.
Here's an explanation that I cribbed from another support question:
When you use the FILEVAR= option, the file-specification is just a placeholder, not an actual filename or a fileref that has been previously assigned to a file. When you do not use the FILEVAR= option you are using the actual filename or a fileref hence allowing to set the permissions using the permissions option (PERMISSION='permission-value'). The PERMISSION value isn't assigned "dynamically" as the active file changes out during multiple passes of the DATA step.
The documentation doesn't mention any such limitations on the new PERMISSION option.
I understand @Tom -- but just relaying information I saw in another internal support case. Maybe it *should* work -- and you might be correct to expect it to -- but I don't want you to waste time trying to make it work if it won't. If you think it's important, I suggest working with SAS Tech Support to pursue possibility of a change. There are workarounds perhaps not as elegant as FILEVAR with PERMISSIONS -- like macro or CALL EXECUTE to define all of the files with permissions ahead of the step.
Chris and Tom,
Thank you for the quick responses. My SAS application is executed within a korn-shell script. Looks like I can control permissions using umask as you have suggested. If this doesn't work for me, I will explore macros, but have minimal experience working with them. Still would love to know why a single file created works perfectly with the PERMISSION option for the FILE statement, while multiple files using FILEVAR does not. At least not for me. 🙂
Again...thank you!
Jackie O.
Note that since you are turning on the group write bit on the files you might will also want to make sure to turn it on for the folder.
You might also want to set the group sticky bit on the folder when it is created. That way all files created in the folder will be in the same group.
mkdir -p myfolder
chmod g+s,g+w myfolder
cd myfolder
umask 002
sas myprogram
Thank you all for your help. Consider this case closed. 🙂
Jackie O
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.