DATA Step, Macro, Functions and more

Running Unix scripts/commands from SAS programs

Reply
Super Contributor
Posts: 275

Running Unix scripts/commands from SAS programs

Hi,
I am trying to accomplish a simple task using SAS & Unix server-
i) Create a shell script in a particular Unix directory which will have FTP commands
ii) Run this shell script from SAS to transfer the required files from server1 to server2.

Step i) is easily done using a data step+file statement+ put statements.
Stepii) is not working and I have tried 3 different ways -
a) X command
X 'sh /SASInt/.../ftp_script.sh &';
b) %macro sample;
%sysexec %str(sh /SASInt/.../ftp_script.sh &)'
c) filename results pipe "sh /SASInt/.../ftp_script.ksh &";

Even if I change the permissions to 777 for ftp_script.sh, it does not work.

Does anyone have suggestions?

Thanks.
Respected Advisor
Posts: 4,173

Re: Running Unix scripts/commands from SAS programs

What exactly is not working? What error do you get?

Can you execute your sh script from a command line window?

Is sh the default shell? You could give %systask a try as there you can explicitly define the shell.
Super Contributor
Posts: 474

Re: Running Unix scripts/commands from SAS programs

Should work, nothing wrong with both methods you described.

Please give us more info about the error.

Cheers from Portugal.

Daniel Santos @ www.cgd.pt.
Super User
Posts: 5,435

Re: Running Unix scripts/commands from SAS programs

I suspect that the final task might be to read these files using SAS?
If this is the case you could give FILENAME FTP a try.

/Linus
Data never sleeps
Super Contributor
Posts: 275

Re: Running Unix scripts/commands from SAS programs

Hi guys,
I will reply to your questions -
Patrick:
1. It does not throw any errors. The log file shows it as executed but I dont see the file being transferred from server1 to server2. So, that means the ftp commands inside the shell script have not worked.
2.yes. I can execute this shell script from my unix command line. It works perfect.
3.I believe korn shell is the default shell. We also have bourne shell but I think the shell need not be changed?
Linus:
The final objective is to move text file/raw files from server1 to server2 where our group's SAS tools/instances are installed.

11 ODS HTML(ID=EGHTML) FILE=EGHTML ENCODING='utf-8' STYLE=EGDefault
11 ! STYLESHEET=(URL="file:///C:/Program%20Files/SAS/Shared%20Files/BIClientStyles/EGDefault.css")
11 ! ATTRIBUTES=("CODEBASE"="http://www2.sas.com/codebase/graph/v91/sasgraph.exe") NOGTITLE NOGFOOTNOTE GPATH=&sasworklocation
11 ! ;
12
13 %gaccessible;
14 X 'sh /SASInt/...../ftp_script.sh &'
14 ! ;
15
16
17 %LET _CLIENTTASKLABEL=;
18 %LET _EGTASKLABEL=;
;

The lines 11-13 and 15-18 are EG specific. They appear for all the codes executed in my EG. So,we can ignore them.

Thanks,
Raj.
SAS Super FREQ
Posts: 8,868

Re: Running Unix scripts/commands from SAS programs

Hi:
Usually the X command is disabled for EG clients. It might be that your SAS administrators have done this at your installation. See these Tech Support Notes:
http://support.sas.com/kb/16/405.html
http://support.sas.com/kb/4/503.html

cynthia
Contributor
Posts: 48

Re: Running Unix scripts/commands from SAS programs

what is the option XCMD value. If XCMD = NOXCMD, then you can not run X command.
Simplest way to do check:
proc options
option=XCMD;
quit;
Contributor
Posts: 74

Re: Running Unix scripts/commands from SAS programs

could it be that your working directory on the unix server (usually your /home) is different from the 'working directory' for the SAS program, which is defaulted to where the software is installed?
N/A
Posts: 0

Re: Running Unix scripts/commands from SAS programs

I think abdullala is on the right track. You gave the complete pathname of the script you wish to run; so, it runs. However, the working directory of the shell is the working directory SAS uses.
If the SAS working directory in not your home directory, and if the ftp commands in your script file do not give the complete pathnames of the files you wish to transfer, then the ftp process will not find the files. However, when you ran the script from the command line the current working directory was your home directory; hence, the files were found and the script succeeded.
Solutions:
1) put the complete pathnames of the files into your script.
2) put a cd command to your home directory (cd ~) into your SAS X command.
Ask a Question
Discussion stats
  • 8 replies
  • 3382 views
  • 0 likes
  • 8 in conversation