- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Yes that was missing and it works...
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
See this thread for a very similar question
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content