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!
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.
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.
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.
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!)
Afraid not, if you call a shell command, it opens the command window.
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;
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;
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!
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.
Ready to level-up your skills? Choose your own adventure.