<?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: Changing character values depending on how many of that character appear in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Changing-character-values-depending-on-how-many-of-that/m-p/104636#M29206</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am probably not the right person for the question, as I know how far away I am from a PRX expert. There are loads of learning materials online, but studying them only makes me feel that I know nothing about nothing. So I started by reading this great paper by Ron Cody:&lt;/P&gt;&lt;P&gt;&lt;A href="http://www2.sas.com/proceedings/sugi29/265-29.pdf" title="http://www2.sas.com/proceedings/sugi29/265-29.pdf"&gt;http://www2.sas.com/proceedings/sugi29/265-29.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt; And I use this:&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/viewer.htm#p1vz3ljudbd756n19502acxazevk.htm" title="http://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/viewer.htm#p1vz3ljudbd756n19502acxazevk.htm"&gt;SAS(R) 9.3 Functions and CALL Routines: Reference&lt;/A&gt; &lt;/P&gt;&lt;P&gt;and this:&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/viewer.htm#p0s9ilagexmjl8n1u7e1t1jfnzlk.htm" title="http://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/viewer.htm#p0s9ilagexmjl8n1u7e1t1jfnzlk.htm"&gt;SAS(R) 9.3 Functions and CALL Routines: Reference&lt;/A&gt;&lt;/P&gt;&lt;P&gt;as my lookup link. That is all I got. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HTH,&lt;/P&gt;&lt;P&gt;Haikuo &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 11 Apr 2013 13:43:18 GMT</pubDate>
    <dc:creator>Haikuo</dc:creator>
    <dc:date>2013-04-11T13:43:18Z</dc:date>
    <item>
      <title>Changing character values depending on how many of that character appear</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Changing-character-values-depending-on-how-many-of-that/m-p/104631#M29201</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm working with a data table that has a variable that has names separated by '\\'.&amp;nbsp; I do not know how many names there are per row.&amp;nbsp; There could be 1 up to 10 names.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I need to do is if there is 1 name to not do anything.&amp;nbsp; If it's 2 names I have to put the word "and" between the names.&amp;nbsp; If it's more than 2 I have to put a comma between the names except for the last occurrences where I have to have "and". &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ex.&lt;/P&gt;&lt;P&gt;William&lt;/P&gt;&lt;P&gt;Bob\\Joe\\Fred&lt;/P&gt;&lt;P&gt;Freddy\\Steve\\Jimmy\Cindy&lt;/P&gt;&lt;P&gt;Wilma\\David&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;results&lt;/P&gt;&lt;P&gt;William&lt;/P&gt;&lt;P&gt;Bob, Joe and Fred&lt;/P&gt;&lt;P&gt;Freddy, Steve, Jimmy and Cindy&lt;/P&gt;&lt;P&gt;Wilma and Dave.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is the code I'm working with.&amp;nbsp; It seems like it can be done in a much cleaner way.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_13656166270573303" jivemacro_uid="_13656166270573303"&gt;
&lt;P&gt;f1 = 'People: ' ;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;if length(trim(left(People))) &amp;gt; 1 then do ;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if count(People, '\\') = 0 then f2 = f1 || ' ' || People ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if count(People, '\\') = 1 then do ;&lt;/P&gt;
&lt;P&gt;&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; People_1 = tranwrd(People, '\\', ' and ') ;&lt;/P&gt;
&lt;P&gt;&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; f2 = catx(' ', f1, People_1) ;&lt;/P&gt;
&lt;P&gt;&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; end ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if count(People, '\\') &amp;gt; 1 then do ;&lt;/P&gt;
&lt;P&gt;&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; lastDelim = find (People, '\\', -400) ;&lt;/P&gt;
&lt;P&gt;&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; if lastDelim ne . then People_ = substr(People, 1, lastDelim-1) || ' and ' || substr(People, lastDelim+2) ; &lt;/P&gt;
&lt;P&gt;&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; else People_ = '' ;&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; &lt;/P&gt;
&lt;P&gt;&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; People_2 = tranwrd(People_, '\\', ',') ;&lt;/P&gt;
&lt;P&gt;&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; f2 = catx(' ', f1, People_2) ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end ;&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help would be appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thank you&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Apr 2013 17:58:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Changing-character-values-depending-on-how-many-of-that/m-p/104631#M29201</guid>
      <dc:creator>jerry898969</dc:creator>
      <dc:date>2013-04-10T17:58:26Z</dc:date>
    </item>
    <item>
      <title>Re: Changing character values depending on how many of that character appear</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Changing-character-values-depending-on-how-many-of-that/m-p/104632#M29202</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not sure if this is 'cleaner', and I am sure someone who speak fluent Perl will come up with better solution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input var $50.;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;William&lt;/P&gt;&lt;P&gt;Bob\\Joe\\Fred&lt;/P&gt;&lt;P&gt;Freddy\\Steve\\Jimmy\\Cindy&lt;/P&gt;&lt;P&gt;Wilma\\David&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; _var=tranwrd(var,'\\',',');&lt;/P&gt;&lt;P&gt;new_var=prxchange("s/,(\w+ *$)/ and \1/o", -1, _var);&lt;/P&gt;&lt;P&gt;drop _var;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Apr 2013 19:45:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Changing-character-values-depending-on-how-many-of-that/m-p/104632#M29202</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2013-04-10T19:45:20Z</dc:date>
    </item>
    <item>
      <title>Re: Changing character values depending on how many of that character appear</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Changing-character-values-depending-on-how-many-of-that/m-p/104633#M29203</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hai.kuo,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you so much for your reply.&amp;nbsp; I have a follow up question.&amp;nbsp; I have multiple columns with this sort of variable but some have a comma already within the data.&amp;nbsp; What would be the best way to do that in that scenario?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ex.&lt;/P&gt;&lt;P&gt;canton, oh\\las vegas, nv\\orlando, fl&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;canton, oh, las vegas, nv, and orlando, fl&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Apr 2013 20:01:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Changing-character-values-depending-on-how-many-of-that/m-p/104633#M29203</guid>
      <dc:creator>jerry898969</dc:creator>
      <dc:date>2013-04-10T20:01:31Z</dc:date>
    </item>
    <item>
      <title>Re: Changing character values depending on how many of that character appear</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Changing-character-values-depending-on-how-many-of-that/m-p/104634#M29204</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In that case, we may need to switch some order:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input var $50.;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;William&lt;/P&gt;&lt;P&gt;Bob\\Joe\\Fred&lt;/P&gt;&lt;P&gt;Freddy\\Steve\\Jimmy\\Cindy&lt;/P&gt;&lt;P&gt;Wilma\\David&lt;/P&gt;&lt;P&gt;canton, oh\\las vegas, nv\\orlando, fl&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;_var=prxchange("s/\\\\([^\\]+ *$)/ and \1/o", -1, var);&lt;/P&gt;&lt;P&gt;&amp;nbsp; new_var=tranwrd(_var,'\\',',');&lt;/P&gt;&lt;P&gt;drop _var;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Apr 2013 20:36:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Changing-character-values-depending-on-how-many-of-that/m-p/104634#M29204</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2013-04-10T20:36:16Z</dc:date>
    </item>
    <item>
      <title>Re: Changing character values depending on how many of that character appear</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Changing-character-values-depending-on-how-many-of-that/m-p/104635#M29205</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you so much Haikuo.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do you know of a good tool to learn perl reg expressions better (book, website,etc.) ? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Apr 2013 13:09:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Changing-character-values-depending-on-how-many-of-that/m-p/104635#M29205</guid>
      <dc:creator>jerry898969</dc:creator>
      <dc:date>2013-04-11T13:09:39Z</dc:date>
    </item>
    <item>
      <title>Re: Changing character values depending on how many of that character appear</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Changing-character-values-depending-on-how-many-of-that/m-p/104636#M29206</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am probably not the right person for the question, as I know how far away I am from a PRX expert. There are loads of learning materials online, but studying them only makes me feel that I know nothing about nothing. So I started by reading this great paper by Ron Cody:&lt;/P&gt;&lt;P&gt;&lt;A href="http://www2.sas.com/proceedings/sugi29/265-29.pdf" title="http://www2.sas.com/proceedings/sugi29/265-29.pdf"&gt;http://www2.sas.com/proceedings/sugi29/265-29.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt; And I use this:&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/viewer.htm#p1vz3ljudbd756n19502acxazevk.htm" title="http://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/viewer.htm#p1vz3ljudbd756n19502acxazevk.htm"&gt;SAS(R) 9.3 Functions and CALL Routines: Reference&lt;/A&gt; &lt;/P&gt;&lt;P&gt;and this:&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/viewer.htm#p0s9ilagexmjl8n1u7e1t1jfnzlk.htm" title="http://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/viewer.htm#p0s9ilagexmjl8n1u7e1t1jfnzlk.htm"&gt;SAS(R) 9.3 Functions and CALL Routines: Reference&lt;/A&gt;&lt;/P&gt;&lt;P&gt;as my lookup link. That is all I got. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HTH,&lt;/P&gt;&lt;P&gt;Haikuo &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Apr 2013 13:43:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Changing-character-values-depending-on-how-many-of-that/m-p/104636#M29206</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2013-04-11T13:43:18Z</dc:date>
    </item>
    <item>
      <title>Re: Changing character values depending on how many of that character appear</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Changing-character-values-depending-on-how-many-of-that/m-p/104637#M29207</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you so much for all your help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Apr 2013 19:42:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Changing-character-values-depending-on-how-many-of-that/m-p/104637#M29207</guid>
      <dc:creator>jerry898969</dc:creator>
      <dc:date>2013-04-11T19:42:59Z</dc:date>
    </item>
  </channel>
</rss>

