Desktop productivity for business analysts and programmers

Unix commands in SAS Enterprise Guide Log

Reply
N/A
Posts: 1

Unix commands in SAS Enterprise Guide Log

Does anyone know of a way to have the unix output show up in the SAS log?

For example the following will display the current directory in the log

x pwd;

But the following won't display anything in the SAS log which I was hoping it would display a list of all files in the directory.

x ls -l;

I understand there are other ways to view this information in enterprise guide but other commands such as the following would be key for some of our less sufisticated users to run without having them learn all the UNIX commands and would allow them to keep track of all the files they have saved on the UNIX server.

x find /filefolder -user user_id -exec ls -sd {} \;

Grand Advisor
Posts: 10,194

Re: Unix commands in SAS Enterprise Guide Log

You can use the commands in file pipes and use that as input to a data step which could be echoed to the log with put statements or printed to the results window.

Valued Guide
Posts: 3,206

Re: Unix commands in SAS Enterprise Guide Log

  filename unxcmd pipe "ls -l   " ;

   DATA WORK._NULL_ ;

     infile unxcmd ;   input;     put _infile_;

   run;quit;

This will run the command wait for the output and process the results. In this case just printing them.

---->-- ja karman --<-----
Grand Advisor
Posts: 9,567

Re: Unix commands in SAS Enterprise Guide Log

You need firstly enter a directory , and then use LS .

x 'cd /home/Arthur' ;

x 'ls -l ' ;

or you can use re-direct operator > to re-direct the output into a file which can be used by SAS later on.

x 'cd /home/Arthur' ;

x 'ls -l  >  ls.txt  ' ;

this will make a ls.txt file which contains the output of LS command  at the current directory (  /home/Arthur ) .

Xia Keshan

New Contributor
Posts: 3

Re: Unix commands in SAS Enterprise Guide Log

Do anyone have idea how to run any command of unix using SAS EG 4.3 .. x commands are not working for every unix command.

I tried using the CALL SYSTEM routine, which works fine for most of the commands. But for some commands like du -g, even CALL SYSTEM is not returning any output.

I used following:-

data _null_;

call system("du -g | tee .....<some log path path>......");

run;

Anyone has idea why log file is not having output for above case ? Other unix commands are working well with this.

Thanks

Super User
Super User
Posts: 6,309

Re: Unix commands in SAS Enterprise Guide Log

Most likely because there is no output to be had.

When I run that command on my system it gives me an error:

> du -g

du: illegal option -- g

usage: du [-a] [-d] [-h|-k] [-r] [-o|-s] [-H|-L] [file ...]

And on Unix the error output normally goes to a different file handle than normal output, so you are not piping anything to the tee command.

This is another place where using the INFILE ... PIPE will work much better. In that case all of the output including the error messages are routed back to you.  Try running this:

data _null_;

  infile 'du -g' pipe ;

  input;

  put _infile_;

run;

New Contributor
Posts: 3

Re: Unix commands in SAS Enterprise Guide Log

thanks Tom Smiley Happy

Valued Guide
Posts: 3,206

Re: Unix commands in SAS Enterprise Guide Log

Sumitb, as you are using the system command the option called XCMD is not blocking you.
Your question is about synchronous asynchronous processing and catching information.

Synchronous Asynchronous processing is about waiting for the command to be ready (synchrone)  or give a kick off and see possible a later moment what happens (asynchrone).

In asynchronous mode you can not have any immediate feedback. You need to take care of receiving that. Think on:  Use redirection to a file or whatever.

That redirection is in Unix possible by using fileio 1 (file for standard output) and 2 (errormessages)    2>1 is telling to put erromessages in the normal output.  redirection >> (append) or > to a file of the standard output.

A lot of Unix internal commands look to have got synchronous support by SAS using EGuide by default. It is receiving that in the log.

The Pipe command approach is forcing synchronous processing and will capture all output after the command has been run.
Do you want this kind of behavior use this one.

The "call system"  and "X"  interfaces are often setup as asynchronous. The output will get lost in the eternity of the vritual world.

XWAIT NOXWAIT is only valid at Windows and not at Unix. X-cmd processing on Mainframe is a quite different challenge as not being there (TSO).

For machine independent logic SAS implemented dopen mopen to bypass OS commands.

Those are supporting the same kind of directory functionality. SAS(R) 9.4 Functions and CALL Routines: Reference, Third Edition 

---->-- ja karman --<-----
New Contributor
Posts: 3

Re: Unix commands in SAS Enterprise Guide Log

Thanks Jaap for the detailed explanation.

It helped me a lot Smiley Happy

Ask a Question
Discussion stats
  • 8 replies
  • 3054 views
  • 3 likes
  • 6 in conversation