SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
jjames1
Fluorite | Level 6

Hello,

I am trying to run a .sh file from sas. I tried the following

data _null_;
call system ('cd /users/smith/report.sh');
run;

But it is not executing my script .

Please help 

6 REPLIES 6
mkeintz
PROC Star
  1. "cd" is change directory.  It will not run the script.
  2. Have you tried the X statement?  It's a global statement (i.e. does not need to be (should not be) inside a DATA step or other PROC step.   See http://www.sascommunity.org/wiki/X_statement

 

  x '/users/smith/report.sh' ;

 

You also need to consider whether you want your SAS program to wait for the X statements complete or not.  If yes, then issue

  options xwait;

somewhere prior to the X statement(s).

 

If not

  options noxwait;

 

 

Note many sysadmins turn off the ability to issue X statements when configuring SAS.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Smr1234
Calcite | Level 5

Hi,

 

I am trying to execute a shell file from a SAS MACRO

I use below code:

filename runoc pipe "/test/space.try.sh";

 

I get message saying there is no logical file name assign to runoc.

Kurt_Bremser
Super User
  • don't hijack a thread that's two years old. Almost nobody will see your question. Open your own thread in SAS Programming.
  • in this new thread, post your whole log (from the filename statement to the ERROR message), using the {i} button.
Kurt_Bremser
Super User

As @mkeintz already noted, cd won't run anything, it just (in UNIX) sets the current working directory of the shell (or, when submitted with x or call system(), the cwd of the SAS session).

The best method for executing external programs is with a filename pipe:

filename oscmd pipe "/users/smith/report.sh 2>&1";

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

filename oscmd clear;

This will catch all output (including error messages from stderr, that's done with the 2>&1 redirection) from the external program in the SAS log.

Babloo
Rhodochrosite | Level 12

Could you please tell me why we use

2>&1?

 

Kurt_Bremser
Super User

@Babloo wrote:

Could you please tell me why we use

2>&1?

 


You should start to read all of a post before answering/questioning:

Quote from my post:

(including error messages from stderr, that's done with the 2>&1 redirection)

A google search for "2>&1" will give you extensive information for why it is done.

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
  • 6 replies
  • 15977 views
  • 3 likes
  • 5 in conversation