<?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: standardize strings variable as names in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/standardize-strings-variable-as-names/m-p/762394#M241389</link>
    <description>Hey &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/393829"&gt;@GingerJJ&lt;/a&gt;, I did in the second program that I included in my post. &lt;BR /&gt;&lt;BR /&gt;Regular expressions can be a bit unclear at first, but they’re extremely powerful at parsing strings with odd conditions. &lt;BR /&gt;&lt;BR /&gt;This link may help as well.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://support.sas.com/rnd/base/datastep/perl_regexp/regexp-tip-sheet.pdf" target="_blank"&gt;https://support.sas.com/rnd/base/datastep/perl_regexp/regexp-tip-sheet.pdf&lt;/A&gt;</description>
    <pubDate>Wed, 18 Aug 2021 22:40:27 GMT</pubDate>
    <dc:creator>maguiremq</dc:creator>
    <dc:date>2021-08-18T22:40:27Z</dc:date>
    <item>
      <title>standardize strings variable as names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/standardize-strings-variable-as-names/m-p/762363#M241370</link>
      <description>&lt;P&gt;I have a variable as participants last name. There are names like:&lt;/P&gt;&lt;P&gt;Jose Cruz Jr&lt;/P&gt;&lt;P&gt;Jose Cruz Jr.&lt;/P&gt;&lt;P&gt;Jose Cruz Jr Jr&lt;/P&gt;&lt;P&gt;Jose Jrare&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, like these&lt;/P&gt;&lt;P&gt;De la Rosa&lt;/P&gt;&lt;P&gt;Maria De la Rosa&lt;/P&gt;&lt;P&gt;Maria De Rosa&lt;/P&gt;&lt;P&gt;De Rosa&lt;/P&gt;&lt;P&gt;Vorde Rosa&lt;/P&gt;&lt;P&gt;Rosa Deloy&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;My question is how I can get rid of the Jr or Jr Jr only at the end of the string, but not in the middle as in 'Jose Jrare'? Also, I want to get rid of De in 'De Rosa', but not in 'Vorde Rosa' or 'Rosa Deloy'.&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Aug 2021 19:24:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/standardize-strings-variable-as-names/m-p/762363#M241370</guid>
      <dc:creator>GingerJJ</dc:creator>
      <dc:date>2021-08-18T19:24:53Z</dc:date>
    </item>
    <item>
      <title>Re: standardize strings variable as names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/standardize-strings-variable-as-names/m-p/762370#M241376</link>
      <description>&lt;P&gt;I think this calls for regular expressions. Let me know if you want me to explain what's going on. I may edit and add descriptions.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dsd;
input name :$25.;
datalines;
Jose Cruz Jr
Jose Cruz Jr.
Jose Cruz Jr Jr
Jose Jrare
De la Rosa
Maria De la Rosa
Maria De Rosa
De Rosa
Vorde Rosa
Rosa Deloy
;
run;

data want;
	set have;
		/* Forgot to add the number. If Jr exists do a separate process. */
		if find(name, "Jr") &amp;gt; 0 then do;
			/* s/ starts the substition. It has a reciprocated / at the end to stop this process. */
			/* I group all the Jr's together with parentheses to treat them as one. */
			/* I then add the $, which looks specifically for the Jr. group at the end of the string. */
			/* I then replace it with a blank by specifying nothing after $/ */
			/* Also trimming names so there isn't any trailing blanks. */
			new_name = prxchange("s/(Jr|Jr.|Jr Jr)$//", -1 , trim(name));
		end;
			/* If it isn't Jr. do another process. */
			else do;
				/* Again, prxchange or substituting starts with "/s */
				/* I want to find two patterns: space (\s) De space (\s), or (|) a string that starts (^) with De. */
				/* Replace it with a space / / */
				/* Also trimming names so there isn't any trailing blanks. */
				new_name = prxchange("s/(\s\De\s|^De)/ /", -1, trim(name));
			end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;TABLE class="table" style="border-spacing: 0;" aria-label="Data Set WORK.WANT"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="header" scope="col"&gt;name&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;new_name&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="data"&gt;Jose Cruz Jr&lt;/TD&gt;
&lt;TD class="data"&gt;Jose Cruz&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="data"&gt;Jose Cruz Jr.&lt;/TD&gt;
&lt;TD class="data"&gt;Jose Cruz&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="data"&gt;Jose Cruz Jr Jr&lt;/TD&gt;
&lt;TD class="data"&gt;Jose Cruz&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="data"&gt;Jose Jrare&lt;/TD&gt;
&lt;TD class="data"&gt;Jose Jrare&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="data"&gt;De la Rosa&lt;/TD&gt;
&lt;TD class="data"&gt;la Rosa&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="data"&gt;Maria De la Rosa&lt;/TD&gt;
&lt;TD class="data"&gt;Maria la Rosa&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="data"&gt;Maria De Rosa&lt;/TD&gt;
&lt;TD class="data"&gt;Maria Rosa&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="data"&gt;De Rosa&lt;/TD&gt;
&lt;TD class="data"&gt;Rosa&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="data"&gt;Vorde Rosa&lt;/TD&gt;
&lt;TD class="data"&gt;Vorde Rosa&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="data"&gt;Rosa Deloy&lt;/TD&gt;
&lt;TD class="data"&gt;Rosa Deloy&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ran this on my local copy of SAS and had some formatting issues. Added a left/trim to left align and trim blanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
		/* Forgot to add the number. If Jr exists do a separate process. */
		if find(name, "Jr") &amp;gt; 0 then do;
			/* s/ starts the substition. It has a reciprocated / at the end to stop this process. */
			/* I group all the Jr's together with parentheses to treat them as one. */
			/* I then add the $, which looks specifically for the Jr. group at the end of the string. */
			/* I then replace it with a blank by specifying nothing after $/ */
			/* Also trimming names so there isn't any trailing blanks. */
			new_name = left(trim(prxchange("s/(Jr|Jr.|Jr Jr)$//", -1 , trim(name))));
		end;
			/* If it isn't Jr. do another process. */
			else do;
				/* Again, prxchange or substituting starts with "/s */
				/* I want to find two patterns: space (\s) De space (\s), or (|) a string that starts (^) with De. */
				/* Replace it with a space / / */
				/* Also trimming names so there isn't any trailing blanks. */
				new_name = left(trim(prxchange("s/(\s\De\s|^De)/ /", -1, trim(name))));
			end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Aug 2021 20:06:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/standardize-strings-variable-as-names/m-p/762370#M241376</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2021-08-18T20:06:21Z</dc:date>
    </item>
    <item>
      <title>Re: standardize strings variable as names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/standardize-strings-variable-as-names/m-p/762378#M241381</link>
      <description>&lt;P&gt;Thank you! Please do explain it a bit.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Aug 2021 20:52:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/standardize-strings-variable-as-names/m-p/762378#M241381</guid>
      <dc:creator>GingerJJ</dc:creator>
      <dc:date>2021-08-18T20:52:15Z</dc:date>
    </item>
    <item>
      <title>Re: standardize strings variable as names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/standardize-strings-variable-as-names/m-p/762394#M241389</link>
      <description>Hey &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/393829"&gt;@GingerJJ&lt;/a&gt;, I did in the second program that I included in my post. &lt;BR /&gt;&lt;BR /&gt;Regular expressions can be a bit unclear at first, but they’re extremely powerful at parsing strings with odd conditions. &lt;BR /&gt;&lt;BR /&gt;This link may help as well.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://support.sas.com/rnd/base/datastep/perl_regexp/regexp-tip-sheet.pdf" target="_blank"&gt;https://support.sas.com/rnd/base/datastep/perl_regexp/regexp-tip-sheet.pdf&lt;/A&gt;</description>
      <pubDate>Wed, 18 Aug 2021 22:40:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/standardize-strings-variable-as-names/m-p/762394#M241389</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2021-08-18T22:40:27Z</dc:date>
    </item>
    <item>
      <title>Re: standardize strings variable as names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/standardize-strings-variable-as-names/m-p/762396#M241390</link>
      <description>&lt;P&gt;Thank you so much!&lt;/P&gt;&lt;P&gt;Just saw your updated response!&lt;/P&gt;&lt;P&gt;Good thing is I found more abnormal patterns in my data and will probably come back with more questions.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Aug 2021 23:02:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/standardize-strings-variable-as-names/m-p/762396#M241390</guid>
      <dc:creator>GingerJJ</dc:creator>
      <dc:date>2021-08-18T23:02:40Z</dc:date>
    </item>
  </channel>
</rss>

