BookmarkSubscribeRSS Feed
amager
Obsidian | Level 7

Hi, 

 

We have a lot of command X in our programs such as Rmdir, del, Dir ... Etc.

 

The problem is that one X command had delete all files, when '&path' macro-variable was empty : 

 

X " rmdir  /Q /S &path";

 

 

My question here :  What the best programming way that you recommended to deal with this case :

 + Check Macro-variable before the X command .eg : check if  '&path'  is empty path ?

 + Any alternative to the famous '\Q \S', we can change it by something else or avoid it laterally ? 

 

How to safe our data from this monster of " rmdir \q \s"  ? 

 

Another question : I identify those command X : "Del, move, copy " to be also less danger than rmdir, can you mention other command x that probably can be danger  ? 

 

I wait your entitlement Dear SAS expert 🙂 

 

P.S : i'm simple developer not admin.

Thanks in advance.

 

 

 

 

 

 

 

8 REPLIES 8
RW9
Diamond | Level 26 RW9
Diamond | Level 26

"What the best programming way that you recommended to deal with this case" - Quite simply don't use SAS to system admin tasks.  There is far better software out there for this type of task, and having a proper admin process in place to create/remove areas, and using version control systems is always the better (if not best) method to achieve this.  Writing some code yourself is going to be lots of work, and likely to break each run opening you up to the danger of deleting whole hard drives.

amager
Obsidian | Level 7

@RW9: we have version control systems so the data is always safe, but need some days to be recover. the purpose is just run x cmd safetly : like check if the path to be deleted exsite and not emplty. some tips like that assure more the command X.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

There is no "safely" with X command, it just passes text out to the operating system.  Its why a lot of places disable that by default.  You have all the tips there, does the path exist (which will also check missing or not).  

But if you have version control systems in place then you should not need to remove anything.

Tom
Super User Tom
Super User

I would recommend creating your own programs to do the actions that you need done.  You can then test these program to make sure they take proper action in all cases.  Then only use your tested programs in your code rather than running any X (system, pipe, etc) command directly in user written code.

 

For SAS that would probably be done by creating a macro or macro library.

amager
Obsidian | Level 7

@Tom That what are doing now. but , accidentally  : an empty &path , in rmdir had delete all file !! 😕 i

 

Tom
Super User Tom
Super User

@amager wrote:

@Tom That what are doing now. but , accidentally  : an empty &path , in rmdir had delete all file !! 😕 i

 


Then update your test suite for that macro and include a test for that case!!  

 

I have a step in a macro that allows users to remove a project directory.  It will only run if the directory is empty.  So it firsts gets a list of all of the files in the directory and checks that it is empty (or only includes some specific filenames that we don't care about). If it is not empty it fails and reports the problem to the log.

 

amager
Obsidian | Level 7

Indeed, we did it already.

 

Also, I suggested to run a macro that search for cmd X in programs, to be checked before validation :

 

filename cmd pipe "findstr /s /n /i /p /r /b ""[xX] .rd|del"" ""&server_sas"" ";

what you think by the way about this regrex expression  :   "[xX] .rd|del", can find 'rd' and 'del' cmd x ?

P.S : I know findstr not match prefectly with regrex but no choice.

Reeza
Super User
Why not use the SAS file functions instead, which have some built in checks? FDELETE

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 8 replies
  • 1842 views
  • 2 likes
  • 4 in conversation