<?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: Working with Strings in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Working-with-Strings/m-p/485947#M126326</link>
    <description>&lt;P&gt;This is to extract and thing after 'with' including 'with',&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
infile cards truncover ;
input var1 $100.;
new_var=prxchange('s/.+(with.+)/$1/io',-1,var1);
cards;
Members United Swaps With Defendants
Members United Swaps With Other Parties
Southwest Swaps With Defendants
Southwest Swaps With Other Parties
WesCorp Swaps With Defendants
WesCorp Swaps With Other Parties
U.S. Central Swaps With Defendants
U.S. Central Swaps With Other Parties
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 10 Aug 2018 20:48:58 GMT</pubDate>
    <dc:creator>Haikuo</dc:creator>
    <dc:date>2018-08-10T20:48:58Z</dc:date>
    <item>
      <title>Working with Strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-Strings/m-p/485941#M126323</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have these observations under the variable "var1":&lt;/P&gt;&lt;P&gt;Members United Swaps With Defendants&lt;BR /&gt;Members United Swaps With Other Parties&lt;BR /&gt;Southwest Swaps With Defendants&lt;BR /&gt;Southwest Swaps With Other Parties&lt;BR /&gt;WesCorp Swaps With Defendants&lt;BR /&gt;WesCorp Swaps With Other Parties&lt;BR /&gt;U.S. Central Swaps With Defendants&lt;BR /&gt;U.S. Central Swaps With Other Parties&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically I would like to create a variable "var2" based on "var1"&amp;nbsp; that looks like this:&lt;/P&gt;&lt;P&gt;With Defendants&lt;BR /&gt;With Other Parties&lt;BR /&gt;With Defendants&lt;BR /&gt;With Other Parties&lt;BR /&gt;With Defendants&lt;BR /&gt;With Other Parties&lt;BR /&gt;With Defendants&lt;BR /&gt;With Other Parties&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone help me out?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Aug 2018 20:32:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-Strings/m-p/485941#M126323</guid>
      <dc:creator>jrdykstr93</dc:creator>
      <dc:date>2018-08-10T20:32:24Z</dc:date>
    </item>
    <item>
      <title>Re: Working with Strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-Strings/m-p/485945#M126324</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if index(var1,"With Defendants") &amp;gt; 0 then var2="With Defendants";
else var2="With Other Parties";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;index() is a character function where the first argument is the string/column you want to search, and second argument is what you want to search for. If that second argument is found, the function returns a number equal to the starting position. Else, it returns 0. So the above looks to see if it contains defendants, and if not, assumes it contains parties. You could add other if else/else logic if necessary.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Aug 2018 20:41:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-Strings/m-p/485945#M126324</guid>
      <dc:creator>cau83</dc:creator>
      <dc:date>2018-08-10T20:41:13Z</dc:date>
    </item>
    <item>
      <title>Re: Working with Strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-Strings/m-p/485946#M126325</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
&amp;nbsp;set have;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;length var2 $20;&amp;nbsp; /* adapt to max length expected */
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;var2 = substr(var1,&amp;nbsp;index(var1,'with'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Check weather you need to check case (upcase / lowcase) of 'with' letters.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Aug 2018 20:43:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-Strings/m-p/485946#M126325</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-08-10T20:43:24Z</dc:date>
    </item>
    <item>
      <title>Re: Working with Strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-Strings/m-p/485947#M126326</link>
      <description>&lt;P&gt;This is to extract and thing after 'with' including 'with',&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
infile cards truncover ;
input var1 $100.;
new_var=prxchange('s/.+(with.+)/$1/io',-1,var1);
cards;
Members United Swaps With Defendants
Members United Swaps With Other Parties
Southwest Swaps With Defendants
Southwest Swaps With Other Parties
WesCorp Swaps With Defendants
WesCorp Swaps With Other Parties
U.S. Central Swaps With Defendants
U.S. Central Swaps With Other Parties
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Aug 2018 20:48:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-Strings/m-p/485947#M126326</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2018-08-10T20:48:58Z</dc:date>
    </item>
    <item>
      <title>Re: Working with Strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-Strings/m-p/486002#M126347</link>
      <description>&lt;P&gt;You may also use the&amp;nbsp;@'character' column pointer.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
infile cards truncover ;
input @'Swaps' new_var &amp;amp;$20.;
cards;
Members United Swaps With Defendants
Members United Swaps With Other Parties
Southwest Swaps With Defendants
Southwest Swaps With Other Parties
WesCorp Swaps With Defendants
WesCorp Swaps With Other Parties
U.S. Central Swaps With Defendants
U.S. Central Swaps With Other Parties
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Cheers.&lt;/P&gt;</description>
      <pubDate>Sat, 11 Aug 2018 03:25:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-Strings/m-p/486002#M126347</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2018-08-11T03:25:29Z</dc:date>
    </item>
    <item>
      <title>Re: Working with Strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-Strings/m-p/486027#M126363</link>
      <description>&lt;P&gt;Better to use FINDW()&amp;nbsp; function .&lt;/P&gt;</description>
      <pubDate>Sat, 11 Aug 2018 11:04:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-Strings/m-p/486027#M126363</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-08-11T11:04:32Z</dc:date>
    </item>
    <item>
      <title>Re: Working with Strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-Strings/m-p/487471#M127031</link>
      <description>&lt;P&gt;I ended up using this code:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;new_var1= strip(substr(var_have,findw(upcase(&lt;SPAN&gt;var_have&lt;/SPAN&gt;),'WITH')+lengthc('with')));&lt;/P&gt;&lt;P&gt;new_var2&amp;nbsp;= strip(substr(var_have,1,findw(upcase(&lt;SPAN&gt;var_have&lt;/SPAN&gt;),'WITH')-1));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Because it turned i needed to make two variables, one before with and one after.&amp;nbsp; I am sure there is better ways to do this, but as of right now this way is working.&amp;nbsp; Thanks for everyone's contribution.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Aug 2018 15:22:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-Strings/m-p/487471#M127031</guid>
      <dc:creator>jrdykstr93</dc:creator>
      <dc:date>2018-08-16T15:22:11Z</dc:date>
    </item>
    <item>
      <title>Re: Working with Strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-Strings/m-p/487624#M127083</link>
      <description>&lt;P&gt;This does not even do what you described.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data t;
  VAR_HAVE = 'Members United Swaps With Other Parties';
  NEW_VAR1 = strip(substr(VAR_HAVE,findw(upcase(VAR_HAVE),'WITH')+lengthc('with')));
  NEW_VAR2 = strip(substr(VAR_HAVE,1,findw(upcase(VAR_HAVE),'WITH')-1));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;TABLE width="523"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="278"&gt;VAR_HAVE&lt;/TD&gt;
&lt;TD width="89"&gt;NEW_VAR1&lt;/TD&gt;
&lt;TD width="156"&gt;NEW_VAR2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Members United Swaps With Other Parties&lt;/TD&gt;
&lt;TD&gt;Other Parties&lt;/TD&gt;
&lt;TD&gt;Members United Swaps&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;A variation on&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;'s reply is the simplest:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  length var2 $20; 
  var2 = substr(var1, findw(var1,'with',' ','i'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What's wrong with that?&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;</description>
      <pubDate>Fri, 17 Aug 2018 02:59:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-Strings/m-p/487624#M127083</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-08-17T02:59:59Z</dc:date>
    </item>
  </channel>
</rss>

