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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
jklaverstijn
Rhodochrosite | Level 12

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

6 REPLIES 6
jklaverstijn
Rhodochrosite | Level 12

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.

Astounding
PROC Star

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?

jklaverstijn
Rhodochrosite | Level 12

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.

Kurt_Bremser
Super User

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.

GoExplore
Obsidian | Level 7

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?

Kurt_Bremser
Super User

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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to connect to databases in SAS Viya

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.

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