SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
aj34321
Quartz | Level 8

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.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
LinusH
Tourmaline | Level 20
Try filename pipe.
Data never sleeps

View solution in original post

7 REPLIES 7
LinusH
Tourmaline | Level 20
Try filename pipe.
Data never sleeps
aj34321
Quartz | Level 8
Thank you LinusH. filename pipe works like anything..
aj34321
Quartz | Level 8

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?

FreelanceReinh
Jade | Level 19

@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;

 

 

aj34321
Quartz | Level 8

Yes that was missing and it works...

aj34321
Quartz | Level 8
Thank you Reeza.. filename pipe worked for me...

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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