<?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: Return first two words in a string and include special characters in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Return-first-two-words-in-a-string-and-include-special/m-p/486829#M287223</link>
    <description>Ahh so close! Many thanks!  The 'm', is this what includes the special characters?  I read somewhere about an M modifier and not sure if this is what this is.</description>
    <pubDate>Tue, 14 Aug 2018 20:37:12 GMT</pubDate>
    <dc:creator>PhatRam33</dc:creator>
    <dc:date>2018-08-14T20:37:12Z</dc:date>
    <item>
      <title>Return first two words in a string and include special characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Return-first-two-words-in-a-string-and-include-special/m-p/486766#M287221</link>
      <description>&lt;P&gt;HI everyone! I've been able to return the first two words of a string and create a third variable with both concatenated.&amp;nbsp;&amp;nbsp;However, I also want to include special characters that could be included in the words within the string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the code&amp;nbsp;I have so far.&amp;nbsp; If you notice, the last two lines do not return the special characters within the word and need to do so as such:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Appreciate any help on this &lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; input; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; str &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$60.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BLUE&lt;/P&gt;
&lt;P&gt;BLUE BLACK&lt;/P&gt;
&lt;P&gt;BLUE GREY BROWN&lt;/P&gt;
&lt;P&gt;BLUE GREEN RED&lt;/P&gt;
&lt;P&gt;BLUE RED YELLOW ORANGE&lt;/P&gt;
&lt;P&gt;BLUE$ YELLOW&lt;/P&gt;
&lt;P&gt;BLUE/ ORANGE GRAY&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; test;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; input;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;w1 = scan(str, &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;w2 = scan(str, &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;length&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; w3 $ &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;30&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;SubStrLength=findc(str, &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;' '&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,-length(str));&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; SubStrLength=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; w3=w1;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;else&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; w3=trim(catx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;' '&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;, w1, w2));&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;drop&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; SubStrLength;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Aug 2018 18:10:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Return-first-two-words-in-a-string-and-include-special/m-p/486766#M287221</guid>
      <dc:creator>PhatRam33</dc:creator>
      <dc:date>2018-08-14T18:10:44Z</dc:date>
    </item>
    <item>
      <title>Re: Return first two words in a string and include special characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Return-first-two-words-in-a-string-and-include-special/m-p/486771#M287222</link>
      <description>&lt;P&gt;The below will give you the right split with the spl char. I am sure you can do the concat work yourself as you seem smart.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data input;

input str $60.;

datalines;
BLUE
BLUE BLACK
BLUE GREY BROWN
BLUE GREEN RED
BLUE RED YELLOW ORANGE
BLUE$ YELLOW
BLUE/ ORANGE GRAY
;


run;

data test;

set input;

w1 = scan(str, 1,' ','m');

w2 = scan(str, 2,' ','m');run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Aug 2018 18:30:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Return-first-two-words-in-a-string-and-include-special/m-p/486771#M287222</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-14T18:30:27Z</dc:date>
    </item>
    <item>
      <title>Re: Return first two words in a string and include special characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Return-first-two-words-in-a-string-and-include-special/m-p/486829#M287223</link>
      <description>Ahh so close! Many thanks!  The 'm', is this what includes the special characters?  I read somewhere about an M modifier and not sure if this is what this is.</description>
      <pubDate>Tue, 14 Aug 2018 20:37:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Return-first-two-words-in-a-string-and-include-special/m-p/486829#M287223</guid>
      <dc:creator>PhatRam33</dc:creator>
      <dc:date>2018-08-14T20:37:12Z</dc:date>
    </item>
  </channel>
</rss>

