So I have been trying to find a way code a file permission in SAS but have been unsucessful so far. I have found this macros online which is supposed to do this but I don't know what I would change in this code so it changes the permissions to my data. Thanks!
macro chmod(libname,dataset,permis=777);
proc sql;
/* get the absolute path of the libname */
select path into: extpath from dictionary.members
where libname="%UPCASE(&LIBNAME)";
/* find out if there are any datasets in the library */
select count(path) into: cnt from dictionary.members
where libname="%UPCASE(&LIBNAME)";
/* if there are datasets...then issue the below command to change the
permissions of the dataset called in this macro to 777 */
%if &cnt > 0 %then %do;
filename chmod pipe "chmod &PERMIS %trim(&extpath)/&dataset..ssd01";
data _null_;
file chmod;
run;
%end;
%mend;
Wow .ssd01 extension is a blast from the past. Weren't V6 datasets named this way? With the digits at the end indicating compatibility groups (little vs big endian etc)? If the OP still has these it must be an application with eternal lifespan. Or maybe you just have very old code and your datasets now have the more modern .sas7bdat extension?
The mode of 777 is indeed dangerous as @Astounding mentioned and would sound alarmbells at our site. Actually 666 would be sufficient but who are we to judge?
Thanks for editing your code, it helps. Still, my advice is to change FILE to INFILE and add an INPUT statement.
- Jan.
Your filename statement doesn't make much sense in a few ways. But basically a filename with the pipe options and the intention to execute that command will be used in a INFILE statement instead of FILE. You then do an INPUT to execute the command and read the standard output. Note that chmod may not output anything when succesful.
The construct you use in the filename (trim, PERMIS) will be verbatim part of the command and are bound to fail. Please enlighten us on what you are trying to achieve. That will help us help you.
Regards,
- Jan.
Your program raises many questions. Let's start with a few basics.
If you were not using a SAS program and just using a Unix command, do you know what a chmod command should look like?
Do you really have SAS data sets that are named with the extension "ssd01"?
Have you checked with your IT department to see if you will get in trouble for using a chmod value of 777?
Wow .ssd01 extension is a blast from the past. Weren't V6 datasets named this way? With the digits at the end indicating compatibility groups (little vs big endian etc)? If the OP still has these it must be an application with eternal lifespan. Or maybe you just have very old code and your datasets now have the more modern .sas7bdat extension?
The mode of 777 is indeed dangerous as @Astounding mentioned and would sound alarmbells at our site. Actually 666 would be sufficient but who are we to judge?
Thanks for editing your code, it helps. Still, my advice is to change FILE to INFILE and add an INPUT statement.
- Jan.
Using 777 on files would get you (figuratively) "Hung, Drawn and Quartered" around here.
The only files that need the execute bit set (for anyone) are programs and shell scripts, and those MUST NOT be writable by anyone than the owner.
I am using SAS EG and my requirement is similar to OP. However, allowxCMD is not enabled on the Unix server. Is there any other way to change file permission from SAS EG?
No. Either have XCMD enabled (there is no logical reason against it), or access by SSH so you can set file permissions manually via commandline.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.