BookmarkSubscribeRSS Feed
StevenPhillips
Calcite | Level 5

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 {} \;

8 REPLIES 8
ballardw
Super User

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.

jakarman
Barite | Level 11

  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 --<-----
Ksharp
Super User

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

sumitb
Calcite | Level 5

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

Tom
Super User Tom
Super User

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;

sumitb
Calcite | Level 5

thanks Tom Smiley Happy

jakarman
Barite | Level 11

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 --<-----
sumitb
Calcite | Level 5

Thanks Jaap for the detailed explanation.

It helped me a lot Smiley Happy

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 8 replies
  • 6754 views
  • 4 likes
  • 6 in conversation