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

Hi all,

 

So I was wondering, can you run the following bit of code within SAS to set a file to read only mode?

 

x attrib r+ C:\My Work\Documents\example.doc;

 

or 

 

%sysexec attrib r+ C:\My Work\Documents\example.doc;

 

I tried running it and it did not work, am I missing something?

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

In your first example you miss quotes:

 

x 'attrib r+ "C:\My Work\Documents\example.doc"';

 

Note the singel quotes around the whole DOS part, and the double quotes around the path - double quotes are needed as there are spaces in the path - this means the actual underlying path is not really like that as old dos does not allow spaces or long paths etc. so the UNC path needs quoting.

 

Although why you are doing it this way is a mystery to me?  If its needs to be secure then post it to a document storage (version/access controlled) such as Sharepoint, or use the VCS on your system.  Otherwise every time you want to do anything you need to unlock run re-lock, which just seems a bit pointless.

View solution in original post

7 REPLIES 7
RW9
Diamond | Level 26 RW9
Diamond | Level 26

In your first example you miss quotes:

 

x 'attrib r+ "C:\My Work\Documents\example.doc"';

 

Note the singel quotes around the whole DOS part, and the double quotes around the path - double quotes are needed as there are spaces in the path - this means the actual underlying path is not really like that as old dos does not allow spaces or long paths etc. so the UNC path needs quoting.

 

Although why you are doing it this way is a mystery to me?  If its needs to be secure then post it to a document storage (version/access controlled) such as Sharepoint, or use the VCS on your system.  Otherwise every time you want to do anything you need to unlock run re-lock, which just seems a bit pointless.

craig159753
Quartz | Level 8

Hi Perfect!

 

I agree a CVS system is far better, however I am unable to use this at this moment in time. 

 

Quick additional question is there a way to stop the command window open and closing, I want it to run like SAS code, with no windows popping out? Because currently when it runs, the command window flashes up quickly.

 

craig159753
Quartz | Level 8

Sorry I explained that poorly, the NOXWAIT means it closes the prompt and I return to SAS automatically, I just want to not see the command prompt pop up at all, even for a split second, I do not want to see it (this is my OCD kicking in!) 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Afraid not, if you call a shell command, it opens the command window.

FreelanceReinh
Jade | Level 19

Hi @craig159753,

 

If you issue the shell command via a pipe, the command prompt should not pop up:

filename doscmd pipe 'attrib +r "C:\My Work\Documents\example.doc"';

data _null_;
infile doscmd;
run;
RahulG
Barite | Level 11

I think you command should be attrib +r instead of attrib r+

 

x attrib +r C:\My Work\Documents\example.doc

 

Even if it do not work then provide full path of attrib.exe i.e. C:\Windows\system32\attrib.exe

 

x C:\Windows\system32\attrib.exe +r C:\My Work\Documents\example.doc;

 

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 3655 views
  • 5 likes
  • 4 in conversation