BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
alepage
Barite | Level 11

Hello,

 

I have a dataset name filelisting.  One of its variable is unixcommand and the first observation look like below

 

sed -i 's/"prod@test.net"//g' /.../sasmacro/email.sas

 

if I execute the above unix command directrly on the terminal via winscp, its works very well and it erase the sting "prod@test.net" from email.sas

 

How do we passed this unix command using 

 

data _null_; 

set filelisting;

call execute('something');

run;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

CALL EXECUTE() is for submitting SAS code.

 

To run an operating system command (so if your SAS session is running on UNIX then it could be a UNXI command) you can use a PIPE.

 

To use an existing variable as the source of the filename (the string that will the command run in the pipe) use the FILEVAR= option of the INFILE statement.  To see if the command tries to send back any messages just read the lines it writes.

 

So if variable UNIXCOMMAND in the dataset FILELISTING has the commands to run then you want something like this:

data _null_; 
  set filelisting;
  infile unix pipe filevar=unixcommand end=eof;
  do while (not eof);
    input;
    put _infile_;
  end;
run;

 

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

CALL EXECUTE() is for submitting SAS code.

 

To run an operating system command (so if your SAS session is running on UNIX then it could be a UNXI command) you can use a PIPE.

 

To use an existing variable as the source of the filename (the string that will the command run in the pipe) use the FILEVAR= option of the INFILE statement.  To see if the command tries to send back any messages just read the lines it writes.

 

So if variable UNIXCOMMAND in the dataset FILELISTING has the commands to run then you want something like this:

data _null_; 
  set filelisting;
  infile unix pipe filevar=unixcommand end=eof;
  do while (not eof);
    input;
    put _infile_;
  end;
run;

 

alepage
Barite | Level 11

Thank you very much

Tom
Super User Tom
Super User

Left off the DO of the DO WHILE statement.  I will correct in the original post.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

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
  • 3 replies
  • 886 views
  • 0 likes
  • 2 in conversation