How do I get output of GREP command in SAS.

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 76
Accepted Solution

How do I get output of GREP command in SAS.

Hi, Im running some GREP commands and was wondering if I can execute GREP command from SAS and the output is directed directly into SAS dataset instead of text file followed by import. Pls guide.

 

 


Accepted Solutions
Solution
‎05-11-2016 01:40 AM
Super User
Posts: 5,424

Re: How do I get output of GREP command in SAS.

Try filename pipe.
Data never sleeps

View solution in original post


All Replies
Solution
‎05-11-2016 01:40 AM
Super User
Posts: 5,424

Re: How do I get output of GREP command in SAS.

Try filename pipe.
Data never sleeps
Frequent Contributor
Posts: 76

Re: How do I get output of GREP command in SAS.

Thank you LinusH. filename pipe works like anything..
Frequent Contributor
Posts: 76

Re: How do I get output of GREP command in SAS.

Hi Linus, Although the code is working but I think I'm doing something wrong in this.

Below is the command I run from unix and I get 300 rows for this sample pattern.

 

grep -H -R 'real time' /path/pattern_2016*

 

In SAS i have written this below macro

 

filename grep_src pipe "grep -H -R &gpattern. &grep_path.&gfilter.";
data grep_&glev._&gstream.;
infile grep_src;
length runtime_str $ 300;
input runtime_str $ 300.;
run;

 

And the output is exactly half of the rows when compared with actual unix executed grep command. 

 

What do you think the issue may be?

Trusted Advisor
Posts: 1,117

Re: How do I get output of GREP command in SAS.


aj34321 wrote:
(...)

And the output is exactly half of the rows when compared with actual unix executed grep command. 

 

What do you think the issue may be?


Hi @aj34321,

 

Your log contains the note

 

NOTE: SAS went to a new line when INPUT statement reached past the end of a line.

doesn't it? This is because with formatted input (input runtime_str $300.;) and the default option FLOWOVER, SAS attempts to read more data from the next record when the record length is less than the format length (here: 300). But this doesn't make sense here and fails. Thus, only one output record is created per two input records.

 

 

Just add the TRUNCOVER option to your INFILE statement and everything should be fine:

 

infile grep_src truncover;

 

 

Frequent Contributor
Posts: 76

Re: How do I get output of GREP command in SAS.

Posted in reply to FreelanceReinhard

Yes that was missing and it works...

Super User
Posts: 19,770

Re: How do I get output of GREP command in SAS.

Frequent Contributor
Posts: 76

Re: How do I get output of GREP command in SAS.

Thank you Reeza.. filename pipe worked for me...
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 1221 views
  • 0 likes
  • 4 in conversation