<?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: PRXPARSE, it should be possible to combine selections?? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/PRXPARSE-it-should-be-possible-to-combine-selections/m-p/33939#M8237</link>
    <description>Hi Wouter.&lt;BR /&gt;
Are you looking for something like that ?&lt;BR /&gt;
[pre]&lt;BR /&gt;
DATA work.test (DROP = regExp) ;&lt;BR /&gt;
	INFILE CARDS DLM = ";" ;&lt;BR /&gt;
	INPUT text :$40. ;&lt;BR /&gt;
	RETAIN regExp ;&lt;BR /&gt;
	IF _N_=1 THEN regExp = PRXPARSE("/(I|i)ncident(\d+).?/") ;&lt;BR /&gt;
	IF PRXMATCH(regExp, text) THEN number = PRXPOSN(regExp, 2, text)+0 ;&lt;BR /&gt;
CARDS ;&lt;BR /&gt;
Incident124&lt;BR /&gt;
No incident at all&lt;BR /&gt;
Incident2 @ 12:00&lt;BR /&gt;
IncidentABC&lt;BR /&gt;
Incident3ABC&lt;BR /&gt;
Incident 3ABC&lt;BR /&gt;
;&lt;BR /&gt;
RUN ;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Regards,&lt;BR /&gt;
Olivier</description>
    <pubDate>Fri, 25 Jul 2008 14:23:22 GMT</pubDate>
    <dc:creator>Olivier</dc:creator>
    <dc:date>2008-07-25T14:23:22Z</dc:date>
    <item>
      <title>PRXPARSE, it should be possible to combine selections??</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PRXPARSE-it-should-be-possible-to-combine-selections/m-p/33938#M8236</link>
      <description>All,&lt;BR /&gt;
&lt;BR /&gt;
I've got a datastep in which I extract a number from a string. But... The strings are changing from time to time, but only the first part before the word "Incident" (sometime there appear some numbers, but I don't need those). So what I can do, is make 2 datasteps with the statements:&lt;BR /&gt;
&lt;BR /&gt;
PATTERN = PRXPARSE("/^Incident/"); --&amp;gt; start from this word&lt;BR /&gt;
&lt;BR /&gt;
PATTERN = PRXPARSE("/\d\d\d\d\d?/"); --&amp;gt; collect the desired number&lt;BR /&gt;
&lt;BR /&gt;
But it must be able to combine these statements, I think? Saves a lot of time and space! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Thanks in advance!</description>
      <pubDate>Thu, 24 Jul 2008 20:41:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PRXPARSE-it-should-be-possible-to-combine-selections/m-p/33938#M8236</guid>
      <dc:creator>Wouter</dc:creator>
      <dc:date>2008-07-24T20:41:10Z</dc:date>
    </item>
    <item>
      <title>Re: PRXPARSE, it should be possible to combine selections??</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PRXPARSE-it-should-be-possible-to-combine-selections/m-p/33939#M8237</link>
      <description>Hi Wouter.&lt;BR /&gt;
Are you looking for something like that ?&lt;BR /&gt;
[pre]&lt;BR /&gt;
DATA work.test (DROP = regExp) ;&lt;BR /&gt;
	INFILE CARDS DLM = ";" ;&lt;BR /&gt;
	INPUT text :$40. ;&lt;BR /&gt;
	RETAIN regExp ;&lt;BR /&gt;
	IF _N_=1 THEN regExp = PRXPARSE("/(I|i)ncident(\d+).?/") ;&lt;BR /&gt;
	IF PRXMATCH(regExp, text) THEN number = PRXPOSN(regExp, 2, text)+0 ;&lt;BR /&gt;
CARDS ;&lt;BR /&gt;
Incident124&lt;BR /&gt;
No incident at all&lt;BR /&gt;
Incident2 @ 12:00&lt;BR /&gt;
IncidentABC&lt;BR /&gt;
Incident3ABC&lt;BR /&gt;
Incident 3ABC&lt;BR /&gt;
;&lt;BR /&gt;
RUN ;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Regards,&lt;BR /&gt;
Olivier</description>
      <pubDate>Fri, 25 Jul 2008 14:23:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PRXPARSE-it-should-be-possible-to-combine-selections/m-p/33939#M8237</guid>
      <dc:creator>Olivier</dc:creator>
      <dc:date>2008-07-25T14:23:22Z</dc:date>
    </item>
    <item>
      <title>Re: PRXPARSE, it should be possible to combine selections??</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PRXPARSE-it-should-be-possible-to-combine-selections/m-p/33940#M8238</link>
      <description>Well, right now I'm using:&lt;BR /&gt;
&lt;BR /&gt;
&lt;I&gt;data test2;&lt;BR /&gt;
set test1;&lt;BR /&gt;
if _n_ = 1 then do;&lt;BR /&gt;
PATTERN = PRXPARSE("/\d\d\d\d\d?/");&lt;BR /&gt;
&lt;BR /&gt;
IF MISSING(PATTERN) THEN DO;&lt;BR /&gt;
PUT "ERROR IN COMPILING REGULAR EXPRESSION";&lt;BR /&gt;
STOP;&lt;BR /&gt;
end;&lt;BR /&gt;
end;&lt;BR /&gt;
RETAIN PATTERN;&lt;BR /&gt;
CALL PRXSUBSTR(PATTERN,test1,START,LENGTH);&lt;BR /&gt;
      IF START GT 0 THEN DO;&lt;BR /&gt;
      NUMBER = SUBSTR(test1,START,LENGTH);&lt;BR /&gt;
      NUMBER = COMPRESS(NUMBER," ");&lt;BR /&gt;
      OUTPUT;&lt;BR /&gt;
   END;&lt;BR /&gt;
run;&lt;/I&gt;&lt;BR /&gt;
&lt;BR /&gt;
Test1 contains data like:&lt;BR /&gt;
&lt;I&gt;Incident 43244 &lt;BR /&gt;
Incident 894232&lt;BR /&gt;
43243 Incident 44322&lt;BR /&gt;
Incident 23&lt;BR /&gt;
988 Incident 4322&lt;/I&gt;&lt;BR /&gt;
&lt;BR /&gt;
So what I need is &lt;B&gt;only&lt;/B&gt; the number after the word &lt;I&gt;"Incident"&lt;/I&gt;. Unfortunately, I can't check your code right now. I assume the &lt;I&gt;(I|i)&lt;/I&gt; part is to make a distintion between capital written &lt;I&gt;"Incidents"&lt;/I&gt;? And you use the &lt;I&gt;PRXMATCH&lt;/I&gt; function, that's the only way I think if it isn't possible to make 1 &lt;I&gt;PRXPARSE&lt;/I&gt; statement in which you state 2 different cases (start from the word &lt;I&gt;"Incident"&lt;/I&gt; with should be possible with the "^" option, and from there the "d's". I'll let you know, thanks!</description>
      <pubDate>Fri, 25 Jul 2008 21:11:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PRXPARSE-it-should-be-possible-to-combine-selections/m-p/33940#M8238</guid>
      <dc:creator>Wouter</dc:creator>
      <dc:date>2008-07-25T21:11:36Z</dc:date>
    </item>
    <item>
      <title>Re: PRXPARSE, it should be possible to combine selections??</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PRXPARSE-it-should-be-possible-to-combine-selections/m-p/33941#M8239</link>
      <description>Hi, &lt;BR /&gt;
  This is a totally old school example, using INDEX and COMPRESS but I threw in PRXMATCH(see below) to compare to INDEX and both PRXMATCH and INDEX  return the same results (if you compare FOUNDIT and FOUNDIT2). The COMPRESS/SUBSTR is not as elegant as the other solution but it does the job.&lt;BR /&gt;
  cynthia&lt;BR /&gt;
   &lt;BR /&gt;
[pre]&lt;BR /&gt;
data prxtest;&lt;BR /&gt;
  length grp $1 string $100;&lt;BR /&gt;
  infile datalines dsd dlm=',';&lt;BR /&gt;
  input grp $ string $;&lt;BR /&gt;
return;&lt;BR /&gt;
datalines;&lt;BR /&gt;
a,"The 1st Incident was when 12345 (Mr. Dumpty) fell off the wall."&lt;BR /&gt;
b,"The 2nd Incident was when 34567 (Ms. Muffet) fell off a stool."&lt;BR /&gt;
c,"Has the 123 word Incident, but there are no numbers after 'Incident'."&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
                     &lt;BR /&gt;
proc print data=prxtest;&lt;BR /&gt;
  title 'What does the data look like';&lt;BR /&gt;
run;&lt;BR /&gt;
                    &lt;BR /&gt;
data checkdata;&lt;BR /&gt;
  length gotnum 8.;&lt;BR /&gt;
  set prxtest;&lt;BR /&gt;
  retain lookfor ;&lt;BR /&gt;
                &lt;BR /&gt;
  if _n_=1 then do; &lt;BR /&gt;
    ** Create pattern with prxparse.; &lt;BR /&gt;
    lookfor = prxparse('/Incident/'); &lt;BR /&gt;
  end;&lt;BR /&gt;
                     &lt;BR /&gt;
    ** Prxmatch returns the location in Arg2,;&lt;BR /&gt;
    ** where ARG1 begins.;&lt;BR /&gt;
    ** Note how prxmatch and index return the same number;&lt;BR /&gt;
    ** Do you really need prxparse/prxmatch?;&lt;BR /&gt;
    ** Will Index function work for your data?;&lt;BR /&gt;
  foundit = prxmatch(lookfor,string);  &lt;BR /&gt;
  foundit2 = index(string,'Incident');&lt;BR /&gt;
                &lt;BR /&gt;
    ** If the pattern has been found;&lt;BR /&gt;
    ** substring out everything AFTER;&lt;BR /&gt;
    ** the word "Incident". Then, compress;&lt;BR /&gt;
    ** out the punctuation and upper and lower case letters.;&lt;BR /&gt;
    ** What should be left are the numbers after the string Incident.;&lt;BR /&gt;
  if foundit gt 0 then do;&lt;BR /&gt;
     gotnum = input((compress(substr(string,foundit+8),'.,;:()','al')),8.0);&lt;BR /&gt;
  end;&lt;BR /&gt;
  else do;&lt;BR /&gt;
    gotnum = .;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
                       &lt;BR /&gt;
proc print data=checkdata;&lt;BR /&gt;
title 'Found "Incident" Got number';&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Fri, 25 Jul 2008 22:35:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PRXPARSE-it-should-be-possible-to-combine-selections/m-p/33941#M8239</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-07-25T22:35:08Z</dc:date>
    </item>
    <item>
      <title>Re: PRXPARSE, it should be possible to combine selections??</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PRXPARSE-it-should-be-possible-to-combine-selections/m-p/33942#M8240</link>
      <description>Yes Olivier, thanks!!&lt;BR /&gt;
&lt;BR /&gt;
I've changed the statement a little bit (because there's a space between the actual number and "Incident", but it works perfectly!!&lt;BR /&gt;
&lt;BR /&gt;
Right now, it is:&lt;BR /&gt;
&lt;BR /&gt;
DATA work.test2  ;&lt;BR /&gt;
	set test;&lt;BR /&gt;
	RETAIN regExp ;&lt;BR /&gt;
	IF _N_=1 THEN regExp = PRXPARSE("/(I|i)ncident\s(\d+).?/") ;&lt;BR /&gt;
	IF PRXMATCH(regExp, text) THEN number = PRXPOSN(regExp, 2,text) ;&lt;BR /&gt;
	run;</description>
      <pubDate>Sat, 26 Jul 2008 10:30:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PRXPARSE-it-should-be-possible-to-combine-selections/m-p/33942#M8240</guid>
      <dc:creator>Wouter</dc:creator>
      <dc:date>2008-07-26T10:30:19Z</dc:date>
    </item>
    <item>
      <title>Re: PRXPARSE, it should be possible to combine selections??</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PRXPARSE-it-should-be-possible-to-combine-selections/m-p/33943#M8241</link>
      <description>Hi Cynthia,&lt;BR /&gt;
&lt;BR /&gt;
The strange thing is, with this code, the result is always 1 when there's no number before the word "incident", and otherwise I get 2 numbers which I couldn't relate to the numbers before "incident".</description>
      <pubDate>Sat, 26 Jul 2008 10:41:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PRXPARSE-it-should-be-possible-to-combine-selections/m-p/33943#M8241</guid>
      <dc:creator>Wouter</dc:creator>
      <dc:date>2008-07-26T10:41:59Z</dc:date>
    </item>
  </channel>
</rss>

