SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
helannivas88
Obsidian | Level 7

Hi,

 

I have written a shell script to call from SAS via X command. The shell script has totally 3 parameters that I have to pass.

I have a pass one parameters as FORMAT 'TEXT' ESCAPECHAR '\' CTRLCHARS 'YES' along with other two parameters. Example as like below

 

X ' /home/test/shellscript.sh USER PWD FORMAT 'TEXT' ESCAPECHAR '\' CTRLCHARS 'YES' ' ;  but ended up in failure. Even I tried with double quotes as like below

X ' /home/test/shellscript.sh "USER" "PWD" "FORMAT 'TEXT' ESCAPECHAR '\' CTRLCHARS 'YES' " ';

X "/home/test/shellscript.sh USER PWD FORMAT 'TEXT' ESCAPECHAR '\' CTRLCHARS 'YES' ";

 

No luck on the SAS code. Please help me to resolve this. Thanks

 

4 REPLIES 4
Kurt_Bremser
Super User

First, build safeguards into your script so that it reports a wrong call.

Next, make sure that you get it working from a commandline.

Then, call your script with a filename pipe:

filename oscmd pipe "/home/test/shellscript.sh USER PWD FORMAT 'TEXT' ESCAPECHAR '\' CTRLCHARS 'YES'  2>&1";

data _null_;
infile oscmd;
input;
put _infile_;
run;

and inspect the SAS log for messages returned from the command.

Ksharp
Super User

use -SET in shell file to pass parameters.
-sysin ...... -set x 'abc' -set n 10 ............

in sas code use %sysget() to get parameter value.
%let x=%sysget(x);
%let n=%sysget(n);

 

 

@Rick_SAS  wrote a blog about it .

Tom
Super User Tom
Super User

Sounds like you just need to make sure you quote things properly.  

Let's look at your examples one by one.

 

X ' /home/test/shellscript.sh USER PWD FORMAT 'TEXT' ESCAPECHAR '\' CTRLCHARS 'YES' ' ; 

So your have given X a series of quoted text and unquoted text.

 

 

' /home/test/shellscript.sh USER PWD FORMAT '
TEXT
' ESCAPECHAR '
\
' CTRLCHARS '
YES
' '

And some of these of the unquoted text is coming immediately after the quoted text which will cause SAS to think you want a special literal, like a date or time value.

In the second one:

 

X ' /home/test/shellscript.sh "USER" "PWD" "FORMAT 'TEXT' ESCAPECHAR '\' CTRLCHARS 'YES' " ';

Now you have added quotes around the outside and changed some of the quotes in string, but you did change or double all of quotes in the middle.

 

The last one looks valid.

X "/home/test/shellscript.sh USER PWD FORMAT 'TEXT' ESCAPECHAR '\' CTRLCHARS 'YES' ";

But perhaps the issue is that the script does not work on the machine where SAS is running? Or for the userid that is actually running the SAS code?

Normally I use a data step to run code so I can read back the messages that the operating system command generates.

data _null_;
  infile "/home/test/shellscript.sh USER PWD FORMAT 'TEXT' ESCAPECHAR '\' CTRLCHARS 'YES' " pipe ;
  input ;
  put _infile_;
run;

You can also add 2>&1 to the end of command to make sure that error message from the log are directed back to SAS instead of appearing on the terminal of the process that launched SAS.

 

 

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1213 views
  • 0 likes
  • 5 in conversation