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.
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?
@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;
Yes that was missing and it works...
See this thread for a very similar question
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.