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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 442 views
  • 0 likes
  • 2 in conversation