<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: txt files I need to pattern match contents on with regular expressions RegEx in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/txt-files-I-need-to-pattern-match-contents-on-with-regular/m-p/237417#M43520</link>
    <description>You may want to look at system commands that you can pass to OS via SAS instead, that may be more efficient. This would be via the X or SYSEXEC command.</description>
    <pubDate>Wed, 02 Dec 2015 18:18:02 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2015-12-02T18:18:02Z</dc:date>
    <item>
      <title>txt files I need to pattern match contents on with regular expressions RegEx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/txt-files-I-need-to-pattern-match-contents-on-with-regular/m-p/237410#M43516</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I have a need to loop through a set of text files and pattern match with RegEx and based on positive hits, I want a simple output of what files contain at least one match of my expression. I have tested my expression against a few RegEx websites and it seems to pass my quality tests. What I don't know how to do is use a “RegEx” search on a file in SAS. Can anyone give me some starter pointers? I am an experienced programmer but new this last spring to SAS. I am willing to read but to date am not sure what function to even be looking at, …or combination of functions. I guess I am a little lost on what "proc import" to use, the files may or may not be fixed, tab, stanza, bla, bla… I just want to read them a line at a time and check for a match once found can skip out of the file and mark it as match found.&amp;nbsp;&amp;nbsp; TIA.&amp;nbsp; -Keith&lt;/P&gt;</description>
      <pubDate>Wed, 02 Dec 2015 18:01:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/txt-files-I-need-to-pattern-match-contents-on-with-regular/m-p/237410#M43516</guid>
      <dc:creator>kjohnsonm</dc:creator>
      <dc:date>2015-12-02T18:01:39Z</dc:date>
    </item>
    <item>
      <title>Re: txt files I need to pattern match contents on with regular expressions RegEx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/txt-files-I-need-to-pattern-match-contents-on-with-regular/m-p/237412#M43518</link>
      <description>&lt;P&gt;There are a number of SAS functions but loot at PRXMATCH.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may also want to look at some reading tricks such as using _infil_ instead of trying to read into variables, possibly wildcard filenaming and the Filename option on the Infile statement.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Dec 2015 18:09:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/txt-files-I-need-to-pattern-match-contents-on-with-regular/m-p/237412#M43518</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-12-02T18:09:13Z</dc:date>
    </item>
    <item>
      <title>Re: txt files I need to pattern match contents on with regular expressions RegEx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/txt-files-I-need-to-pattern-match-contents-on-with-regular/m-p/237417#M43520</link>
      <description>You may want to look at system commands that you can pass to OS via SAS instead, that may be more efficient. This would be via the X or SYSEXEC command.</description>
      <pubDate>Wed, 02 Dec 2015 18:18:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/txt-files-I-need-to-pattern-match-contents-on-with-regular/m-p/237417#M43520</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-12-02T18:18:02Z</dc:date>
    </item>
    <item>
      <title>Re: txt files I need to pattern match contents on with regular expressions RegEx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/txt-files-I-need-to-pattern-match-contents-on-with-regular/m-p/237425#M43524</link>
      <description>&lt;P&gt;Here is something&amp;nbsp;may get you&amp;nbsp;started (Windows version), tweak it to&amp;nbsp;accommodate your environment.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;filename x pipe 'dir \\yourfolder\*.txt /s /b'; /*This is pipe in all of the dir result into fileref:x*/

data want;

infile x truncover;

input fname $100.;/*this is to get the text file name*/

infile dummy filevar=fname end=last;

do while(not last);

input content $100.; /*this is to get the content of each text file*/

texfilename=fname;

/*here is where to do your RegEx match*/

output;

end;

run;

filename x clear;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Dec 2015 18:46:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/txt-files-I-need-to-pattern-match-contents-on-with-regular/m-p/237425#M43524</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2015-12-02T18:46:13Z</dc:date>
    </item>
    <item>
      <title>Re: txt files I need to pattern match contents on with regular expressions RegEx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/txt-files-I-need-to-pattern-match-contents-on-with-regular/m-p/237439#M43527</link>
      <description>&lt;P&gt;Excellent advice from both, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw﻿&lt;/a&gt;&amp;nbsp;and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt;! And a nice, practical example from &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4877"&gt;@Haikuo﻿&lt;/a&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you go the data step route, you could combine &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw﻿&lt;/a&gt;'s tips with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4877"&gt;@Haikuo﻿&lt;/a&gt;'s code and, e.g., use the automatic variable _INFILE_ rather than a newly created variable CONTENT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example 10 of the &lt;A href="http://support.sas.com/documentation/cdl/en/lestmtsref/68024/HTML/default/viewer.htm#n1rill4udj0tfun1fvce3j401plo.htm" target="_blank"&gt;INFILE statement documentation&lt;/A&gt;&amp;nbsp;could also be interesting. They read the external file names from a text file, which would be preferable to the pipe approach if the .txt files were located in various different folders.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;I was just playing around with the code presented there and verified that it is possible to skip the rest of a (potentially huge) file, as soon as&amp;nbsp;a match was found, and then continue with the next file:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do until(prxmatch('/your RegEx expression/', _infile_));
  input;
end;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The above DO loop would replace the&amp;nbsp;&lt;FONT face="courier new,courier"&gt;do while(^eof); ... end;&lt;/FONT&gt; there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Dec 2015 20:04:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/txt-files-I-need-to-pattern-match-contents-on-with-regular/m-p/237439#M43527</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2015-12-02T20:04:07Z</dc:date>
    </item>
    <item>
      <title>Re: txt files I need to pattern match contents on with regular expressions RegEx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/txt-files-I-need-to-pattern-match-contents-on-with-regular/m-p/239882#M44197</link>
      <description>&lt;P&gt;Thanks for the replies; I am not on my game today because I cannot seem to make any of these ideas produce except the use&lt;/P&gt;
&lt;P&gt;prxparse. I will try again later.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was able to get a simple data set to work with the command&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	if _N_=1 then
	do;
	retain PerlExpression;
		pattern="/(?!0)(?!9[0-9][0-9])\d{3}[-.]{1}(?!00)\d{2}/";
		PerlExpression=prxparse(pattern);
/*		put PerlExpression;*/
	end;
	array match[26] $ 105;
	input data_line $100.;
	position=prxmatch(PerlExpression, data_line);
	mA='Matched Position: ';
	mS='String: ';
	mL='Whole line:';
	if position ^= 0 then
	do;
		current_match = substr(data_line, position,5 );
		put mA position mS current_match mL data_line;
	end;
datalines;
123456789012345678901234567890123456789012345678901234567890123 123-45                             0
023456789012345678901234567890123456789012345678901234567890123 123.45                             0
12345678901234567890123456789-01                                                                    &lt;BR /&gt;123456789012345678901234567 89-01&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
000000000000000000000000000000000000000000000000000000000000003 123 45                             0
14:56.456                                                                                           
45:32                                                                                               
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Dec 2015 23:46:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/txt-files-I-need-to-pattern-match-contents-on-with-regular/m-p/239882#M44197</guid>
      <dc:creator>kjohnsonm</dc:creator>
      <dc:date>2015-12-17T23:46:05Z</dc:date>
    </item>
    <item>
      <title>Re: txt files I need to pattern match contents on with regular expressions RegEx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/txt-files-I-need-to-pattern-match-contents-on-with-regular/m-p/240071#M44259</link>
      <description>&lt;P&gt;I finally was able to get the pipe syntax to at least run, I am not 100% sure but it seems to open the file up for viewing.&amp;nbsp; In my case I eventually want to process every *.txt file on my Network file system so this does not work for my needs but is interesting.&amp;nbsp;&amp;nbsp;&amp;nbsp; I was able to get something like this to work for me to a degree:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename myFile 'D:\The_Directory_path\That_file.txt';
data want;
      infile myFile truncover scanover;
      input line   $4096.;
run;
proc contents data=want;
run;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In my logs I get data like this:&lt;/P&gt;
&lt;P&gt;747&amp;nbsp; filename myFile 'D:\The_Directory_path\That_file.txt';&lt;BR /&gt;748&amp;nbsp; data want;&lt;BR /&gt;749&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; infile myFile truncover scanover;&lt;BR /&gt;750&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input line&amp;nbsp;&amp;nbsp; $4096.;&lt;BR /&gt;751&amp;nbsp; run;&lt;BR /&gt;&lt;BR /&gt;NOTE: The infile MYFILE is:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Filename=D:\The_Directory_path\That_file.txt,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RECFM=V,LRECL=32767,File Size (bytes)=431,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;Last Modified&lt;/STRONG&gt;=18Dec2015:09:52:12,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;Create Time&lt;/STRONG&gt;=17Nov2015:10:13:37&lt;BR /&gt;&lt;BR /&gt;NOTE: 18 records were read from the infile MYFILE.&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;The minimum record length was&lt;/STRONG&gt; 0.&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;The maximum record length was&lt;/STRONG&gt; 50.&lt;BR /&gt;NOTE: The data set WORK.WANT has 18 observations and 1 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; real time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.05 seconds&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cpu time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.03 seconds&lt;/P&gt;
&lt;P&gt;752&amp;nbsp; proc contents data=want;&lt;BR /&gt;753&amp;nbsp; run;&lt;BR /&gt;&lt;BR /&gt;NOTE: PROCEDURE CONTENTS used (Total process time):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; real time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.01 seconds&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cpu time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.01 seconds&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does anyone know how to trap Max/Min, and the time date created or modified in macros vars?&amp;nbsp; I could use the metadata&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&amp;nbsp; I of course already have the file name and path in my program that this eventually fits into...&amp;nbsp; TIA.&amp;nbsp; -KJ&lt;/P&gt;</description>
      <pubDate>Fri, 18 Dec 2015 19:07:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/txt-files-I-need-to-pattern-match-contents-on-with-regular/m-p/240071#M44259</guid>
      <dc:creator>kjohnsonm</dc:creator>
      <dc:date>2015-12-18T19:07:49Z</dc:date>
    </item>
    <item>
      <title>Re: txt files I need to pattern match contents on with regular expressions RegEx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/txt-files-I-need-to-pattern-match-contents-on-with-regular/m-p/240073#M44261</link>
      <description>&lt;P&gt;PS&lt;/P&gt;
&lt;P&gt;I tried this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc print data=dictionary.tables;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This errors because I am not using a Libref.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Dec 2015 19:12:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/txt-files-I-need-to-pattern-match-contents-on-with-regular/m-p/240073#M44261</guid>
      <dc:creator>kjohnsonm</dc:creator>
      <dc:date>2015-12-18T19:12:29Z</dc:date>
    </item>
    <item>
      <title>Re: txt files I need to pattern match contents on with regular expressions RegEx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/txt-files-I-need-to-pattern-match-contents-on-with-regular/m-p/240093#M44264</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*
You could try this
I have limited to 10 obs, as sometimes it takes long to run if 
you have many tables
*/

proc print data=sashelp.vtable(obs=10);
run;

/*
The reason yours does not work is that except one occasion, 
SAS library name is limited to 8 characters, while 'dictionary'
is 10. The following is that one occasion
*/
proc sql inobs=10;
	select * from dictionary.tables
	;
quit;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Dec 2015 20:03:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/txt-files-I-need-to-pattern-match-contents-on-with-regular/m-p/240093#M44264</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2015-12-18T20:03:38Z</dc:date>
    </item>
    <item>
      <title>Re: txt files I need to pattern match contents on with regular expressions RegEx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/txt-files-I-need-to-pattern-match-contents-on-with-regular/m-p/240112#M44272</link>
      <description>&lt;P&gt;...and in my example this where limits me to just my data set want.&amp;nbsp; ...and anything i might have in my work libname.&amp;nbsp; Thanks for the knowledge.&amp;nbsp; thats helps a lot!&amp;nbsp;&amp;nbsp; -KJ&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql inobs=10;
    select * from dictionary.tables
    where libname='WORK' or memname='WANT';
    ;
quit;


proc print data=sashelp.vtable;
where libname='WORK' or memname='WANT';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Dec 2015 21:19:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/txt-files-I-need-to-pattern-match-contents-on-with-regular/m-p/240112#M44272</guid>
      <dc:creator>kjohnsonm</dc:creator>
      <dc:date>2015-12-18T21:19:41Z</dc:date>
    </item>
  </channel>
</rss>

