DATA Step, Macro, Functions and more

SAS X Command and Read-Only

Accepted Solution Solved
Reply
Contributor
Posts: 39
Accepted Solution

SAS X Command and Read-Only

[ Edited ]

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!


Accepted Solutions
Solution
‎05-09-2016 05:36 AM
Super User
Super User
Posts: 7,430

Re: SAS X Command and Read-Only

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


All Replies
Solution
‎05-09-2016 05:36 AM
Super User
Super User
Posts: 7,430

Re: SAS X Command and Read-Only

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.

Contributor
Posts: 39

Re: SAS X Command and Read-Only

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.

 

Super User
Super User
Posts: 7,430

Re: SAS X Command and Read-Only

Contributor
Posts: 39

Re: SAS X Command and Read-Only

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!) 

Super User
Super User
Posts: 7,430

Re: SAS X Command and Read-Only

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

Trusted Advisor
Posts: 1,115

Re: SAS X Command and Read-Only

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;
Regular Contributor
Posts: 242

Re: SAS X Command and Read-Only

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;

 

 

☑ This topic is solved.

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

Discussion stats
  • 7 replies
  • 437 views
  • 4 likes
  • 4 in conversation