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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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