<?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 in datastep in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PRXPARSE-in-datastep/m-p/626720#M184878</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/55140"&gt;@nkm1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems that SAS adds trailing blanks at the end of the 'a' variable:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Test:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2;
	set test1;
	i=tranwrd(a," ","X");
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture d’écran 2020-02-23 à 14.44.29.png" style="width: 200px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/36333i2332A554F405FB87/image-size/small?v=v2&amp;amp;px=200" role="button" title="Capture d’écran 2020-02-23 à 14.44.29.png" alt="Capture d’écran 2020-02-23 à 14.44.29.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To correct it, you can either do :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2;
	set test1;
	retain patternID_1 patternID_2 patternID_3;

	if _n_=1 then do;
			patternID_1=prxparse('/UNIT1A\s*$/i'); /*add \s* */
			patternID_2=prxparse('/UNIT\s*$/i'); /*add \s* */
			patternID_3=prxparse('/cat\s*$/i'); /*add \s* */
	end;
	b=prxmatch(patternID_1, a);
	c=prxmatch(patternID_2, a);
	d=prxmatch(patternID_3, a);
run;

proc print data=test2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2;
	set test1;

	retain patternID_1 patternID_2 patternID_3;

	if _n_=1 then do;
			patternID_1=prxparse('/UNIT1A$/i'); 
			patternID_2=prxparse('/UNIT$/i');
			patternID_3=prxparse('/cat$/i');
	end;
	b=prxmatch(patternID_1, trim(a)); /*add trim(a) */
	c=prxmatch(patternID_2, trim(a)); /*add trim(a) */
	d=prxmatch(patternID_3, trim(a)); /*add trim(a) */
run;

proc print data=test2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 23 Feb 2020 13:47:26 GMT</pubDate>
    <dc:creator>ed_sas_member</dc:creator>
    <dc:date>2020-02-23T13:47:26Z</dc:date>
    <item>
      <title>PRXPARSE in datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PRXPARSE-in-datastep/m-p/626718#M184877</link>
      <description>&lt;P&gt;Hi, I am not getting why this program is not giving me expected result. Is there any issue of compiling prxparse as I was expecting atleast one of b c d variable have value. but it is only populated for D for first row as it was having cat. but i was expecting c and d also populated for second and third row bit it is not. Is there any specific regarding prxparse that we cannot use for multiple time in same code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1;
a = 'there is a cat' ;
output;
a = 'IT IS UNIT1A' ;
output;
a = 'IT IS unit' ;
output;
run;

data test2;
set test1;
retain patternID_1 patternID_2 patternID_3;
if _n_ = 1 then do;
patternID_1 = prxparse('/UNIT1A$/i');
patternID_2 = prxparse('/UNIT$/i');
patternID_3 = prxparse('/cat$/i');
end;

b = prxmatch(patternID_1,a);
c = prxmatch(patternID_2,a);
d = prxmatch(patternID_3,a);
run;

proc print data=test2;run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 23 Feb 2020 13:33:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PRXPARSE-in-datastep/m-p/626718#M184877</guid>
      <dc:creator>nkm1</dc:creator>
      <dc:date>2020-02-23T13:33:21Z</dc:date>
    </item>
    <item>
      <title>Re: PRXPARSE in datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PRXPARSE-in-datastep/m-p/626720#M184878</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/55140"&gt;@nkm1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems that SAS adds trailing blanks at the end of the 'a' variable:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Test:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2;
	set test1;
	i=tranwrd(a," ","X");
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture d’écran 2020-02-23 à 14.44.29.png" style="width: 200px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/36333i2332A554F405FB87/image-size/small?v=v2&amp;amp;px=200" role="button" title="Capture d’écran 2020-02-23 à 14.44.29.png" alt="Capture d’écran 2020-02-23 à 14.44.29.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To correct it, you can either do :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2;
	set test1;
	retain patternID_1 patternID_2 patternID_3;

	if _n_=1 then do;
			patternID_1=prxparse('/UNIT1A\s*$/i'); /*add \s* */
			patternID_2=prxparse('/UNIT\s*$/i'); /*add \s* */
			patternID_3=prxparse('/cat\s*$/i'); /*add \s* */
	end;
	b=prxmatch(patternID_1, a);
	c=prxmatch(patternID_2, a);
	d=prxmatch(patternID_3, a);
run;

proc print data=test2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2;
	set test1;

	retain patternID_1 patternID_2 patternID_3;

	if _n_=1 then do;
			patternID_1=prxparse('/UNIT1A$/i'); 
			patternID_2=prxparse('/UNIT$/i');
			patternID_3=prxparse('/cat$/i');
	end;
	b=prxmatch(patternID_1, trim(a)); /*add trim(a) */
	c=prxmatch(patternID_2, trim(a)); /*add trim(a) */
	d=prxmatch(patternID_3, trim(a)); /*add trim(a) */
run;

proc print data=test2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 23 Feb 2020 13:47:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PRXPARSE-in-datastep/m-p/626720#M184878</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-23T13:47:26Z</dc:date>
    </item>
    <item>
      <title>Re: PRXPARSE in datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PRXPARSE-in-datastep/m-p/626754#M184889</link>
      <description>&lt;P&gt;SAS strings are fixed-length.&lt;/P&gt;
&lt;P&gt;Once the length for A is determined in a data step, it cannot change.&lt;/P&gt;
&lt;P&gt;So if the value you save does not use all the length, the rest of the string contains spaces.&lt;/P&gt;</description>
      <pubDate>Sun, 23 Feb 2020 21:04:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PRXPARSE-in-datastep/m-p/626754#M184889</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-02-23T21:04:37Z</dc:date>
    </item>
    <item>
      <title>Re: PRXPARSE in datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PRXPARSE-in-datastep/m-p/626759#M184890</link>
      <description>&lt;P&gt;Looks like it is doing what you asked.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;3015  data test1;
3016   do a='there is a cat','IT IS UNIT1A','IT IS unit' ;
3017     b = prxmatch('/UNIT1A$/i',a);
3018     c = prxmatch('/UNIT$/i',a);
3019     d = prxmatch('/cat$/i',a);
3020     put (_all_) (=);
3021     output;
3022   end;
3023  run;

a=there is a cat b=0 c=0 d=12
a=IT IS UNIT1A b=0 c=0 d=0
a=IT IS unit b=0 c=0 d=0&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Did you want to trim the value of A?&lt;/P&gt;
&lt;PRE&gt;3042  data test1;
3043   do a='there is a cat','IT IS UNIT1A','IT IS unit' ;
3044     b = prxmatch('/UNIT1A$/i',trim(a));
3045     c = prxmatch('/UNIT$/i',trim(a));
3046     d = prxmatch('/cat$/i',trim(a));
3047     put (_all_) (=);
3048     output;
3049   end;
3050  run;

a=there is a cat b=0 c=0 d=12
a=IT IS UNIT1A b=7 c=0 d=0
a=IT IS unit b=0 c=7 d=0
&lt;/PRE&gt;</description>
      <pubDate>Sun, 23 Feb 2020 21:14:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PRXPARSE-in-datastep/m-p/626759#M184890</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-23T21:14:04Z</dc:date>
    </item>
  </channel>
</rss>

