You are under my command (prompt)

32

In his blog, Jared details the hoops one must jump through to convince SAS to run system shell commands (such as the X command and SYSTASK) from SAS Enterprise Guide.

Here is the explanation: SAS Enterprise Guide is a client application, and SAS runs as a server application. When launched as a server, SAS disables access to shell commands as a safeguard. You wouldn't want just anyone with access to your server to issue "rm *" or "format c:" commands, now would you? (You're welcome.)

When SAS and Enterprise Guide are running on the same machine, it does seem overprotective to prevent you from issuing shell commands on your own box. You can use Jared's notes to re-enable the X command (using the -ALLOWXCMD option or the older double-negative version: -NONOXCMD).

But what if you could avoid those complicated steps and simply represent your local machine shell script as a step in your SAS Enterprise Guide project? That's exactly what the "System Command" custom task allows you to do.

system command process flow
system command window

We provide this task as an example of a custom task that you can use to extend your SAS Enterprise Guide features. In fact, we provide about 20 such examples, with source code, that you can use "as is" or modify as you wish.

What are you waiting for? Download this custom task and take back command.

Share

About Author

Chris Hemedinger

Senior Manager, SAS Online Communities

+Chris Hemedinger is the manager of SAS Online Communities. Since 1993, Chris has worked for SAS as an author, a software developer, an R&D manager and a consultant. Inexplicably, Chris is still coasting on the limited fame he earned as an author of SAS For Dummies.  He also hosts the SAS Tech Talk webcasts each year from SAS Global Forum, connecting viewers with smart people from SAS R&D and the impressive work that they do.

32 Comments

  1. Simon Arnold on

    Hi Chris, I am an Instructor here in Marlow and I am doing some work for a customer who is moving to EG from PC SAS and there is a certain amount of "resistance". One thing that has come up is the X command and this looks like it might be a solution, however before I get too excited, does this work if you have EG on your PC and you are connecting to SAS on a server somewhere. In other words how you would expect to use EG.

    Of course the other issue to raise its head is DDE. I have worked out one solution but would be interested in any others you may have. Many thanks in advance!

    Simon

  2. Hi Chris --

    I just discovered this add-in and it works great, thank you for posting this. My only question is this: is it possible to use the system command add-in with a stored process?

  3. Thanks Chris. I was hoping to avoid the X command, but I will look into your potential solution. Thanks for the quick response by the way!

  4. Pingback: Using the X and SYSTASK commands from SAS Enterprise Guide - The SAS Dummy

  5. Pingback: 11 super-useful custom tasks for SAS Enterprise Guide - The SAS Dummy

  6. Hi Chris,

    I've been using this command prompt successfully under EG 5.1 but have just been upgraded to 6.1 and it no longer works? Is there something I am doing wrong?

    No errors show up in the log but it isn't doing what it's supposed to. Any ideas?

    warm regards
    Steve

    • Chris Hemedinger
      Chris Hemedinger on

      Steve, the same add-in DLL works in 6.1. Some things to check: is the custom task DLL in the expected location? Did you use Tools->Add-In Manager to register it, or did you drop it into one of the designated "Custom" folders (such as %appdata%\SAS\EnterpriseGuide\6.1\Custom)? The latter approach can be a bit more reliable.

      • You're a life saver. I was using the Add-In Manager and it was showing up with no problems at all, just not working.

        I had to create the Custom folder but it worked straight away.

        Thank you very much for your help, much appreciated.

  7. Hi Chris,

    Is it possible to declare or pass macro variables to commands in the command prompt task when the local session is disabled? We are going through a SAS platform migration, and we will no longer be able to execute code on a Local session. It will all be done on a UNIX server.

    We are looking for alternative solutions within SAS EG to accomplish what we need to keep our processes clean. But a number of our processes copy and delete local files, create and delete folders, etc. We've been struggling to find a SAS solution when we can't use a Local session. We can incorporate non-SAS solutions, but it will create some additional risk for control breaks, hopping between platforms mid-process.

    Any help or suggestions you might have are appreciated.

      • Hi Chris, just want to add my vote for this task supporting macro variables! This would be incredibly useful for us as we create many reports with either the date or client name in the title crated via macros. At the moment I use the task to open up the folder containing these files but would be much better if it opened the actual files.
        cheers
        Steve

  8. Tim Walters on

    I couldn't get this to work. When I tried to access it from the EG add-in manager, I received this error message: Could not load file or assembly ‘SASCustomExamples’ or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515).

  9. Hi Chris
    Does "system commands" work with EG 7.1? I unlockded dll but when i try to register the addin the following error

    Unable to load file EGAddin4.dll
    Error: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

    The error above is missing if i load files SASCustomExample.ddl and SASCustomExamplesVB.ddl

    warm regards
    Alexis

  10. Hi Chris,

    First of all, thanks a lot for this task.

    We are about to migrate our SAS projects to a SAS Server. So the %SYSEXEC command wont be available,so I think this could be the solution.

    I've being playing a bit with the task. I have some projects that copy a file wich name is build out of macro variables so I would need the macrovariable enhancement. To achieve this goal I export the comands to .bat file and then execute this from your task. that was a solution.

    But there is two things left...

    - How can i know if the command was executed succesfully?. When using %SYSEXEC the macro variable &SYSRC got that information. Is there a way to get this info from your task

    - When a command fail the task won't execute the rest of commans even if you separate them with &, || ...

    for example, if we set file2.txt as read-only:

    copy /Y file1.txt file2.txt || echo WRONG > log.txt

    Wont write anything to log.txt (even if i write this to a .bat file and then execute it)

    Is there a way to force the execution of all the commands??

    Best regards,
    Gonzalo

  11. Pingback: SAS Enterprise Guide for SAS programmers - The SAS Dummy

    • Chris Hemedinger
      Chris Hemedinger on

      Brian, the answer is No. SAS University Edition uses SAS Studio, which runs in your browser and would not be able to run executable commands outside of that environment. And if you're trying to run shell commands within the SAS session (using SYSTASK or FILENAME PIPE), that's not enabled in the SAS University Edition virtual machine (NOXCMD is set, and cannot be changed).

  12. Pingback: Custom tasks for SAS Enterprise Guide: Q&A - The SAS Dummy

  13. Hi Chris, how can I write a command using special caracter like "é" and "í" if my file path there are these caracteres? I tried, but didin't work. cal help me, please?

    • Chris Hemedinger
      Chris Hemedinger on

      Ronaldo, some other readers had the same problem (see other comments). The trick is that the Windows CMD console does not support UTF-8 natively, so one must explicitly set the OEM codepage if you're using non-ASCII characters. You can avoid the characters in your script (assuming these are file paths) by specifying the shorter 8.3 versions of the names. You can discover those names for a given path by issuing "dir /X" at a command prompt.

  14. Ricardo Neves on

    Hi Chris,

    first of all thank you for this awesome solution!

    I'm using this task to run a python script from the SAS EG process flow. Is there a way to see the output of the script (even if it is outside SAS EG)? I can't see error messages or the outputs I added on the log of the task.

    Thanks in advance,
    Ricardo Neves

    • Chris Hemedinger
      Chris Hemedinger on

      Glad you find it useful! Alas, the task funnels back only the STDOUT from the command, and not any of the other artifacts. There are ways to add such things to custom tasks, but that's more development in the task source code.

Leave A Reply

Back to Top