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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 7 replies
  • 6713 views
  • 0 likes
  • 4 in conversation