SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

file permission

Accepted Solution Solved
Reply
Regular Learner
Posts: 1
Accepted Solution

file permission

[ Edited ]

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;


Accepted Solutions
Solution
‎06-07-2016 05:08 PM
Super Contributor
Posts: 408

Re: file permission

[ Edited ]

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.

View solution in original post


All Replies
Super Contributor
Posts: 408

Re: file permission

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.

Super User
Posts: 5,084

Re: file permission

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?

Solution
‎06-07-2016 05:08 PM
Super Contributor
Posts: 408

Re: file permission

[ Edited ]

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.

Super User
Posts: 6,941

Re: file permission

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 16

Re: file permission

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?

Super User
Posts: 6,941

Re: file permission

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 1018 views
  • 0 likes
  • 5 in conversation