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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 4 replies
  • 891 views
  • 0 likes
  • 5 in conversation