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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 1483 views
  • 0 likes
  • 2 in conversation