<?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: How to extract string of words into a new variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-string-of-words-into-a-new-variable/m-p/841267#M332637</link>
    <description>one, sorry mistype</description>
    <pubDate>Fri, 28 Oct 2022 07:57:31 GMT</pubDate>
    <dc:creator>Jedrzej</dc:creator>
    <dc:date>2022-10-28T07:57:31Z</dc:date>
    <item>
      <title>How to extract string of words into a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-string-of-words-into-a-new-variable/m-p/841258#M332633</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I would like to split my variable in a way that if there are more words then 10 it would extract all words&amp;gt;10 into a new variable and the old one will have only ten words.&lt;/P&gt;&lt;P&gt;example&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;infile cards truncover;&lt;BR /&gt;input str $char150.;&lt;BR /&gt;cards;&lt;BR /&gt;New Year Copenhagen is the Capital of Denmark Jensen is a´defunct British manufacturer of sports cars Another line&amp;nbsp;Paris is a capital of France&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and the output should be&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;str(New Year Copenhagen is the Capital of Denmark Jensen is)&lt;/P&gt;&lt;P&gt;str1(is a´defunct British manufacturer of sports cars Another line)&lt;/P&gt;&lt;P&gt;str2(Paris is a capital of France)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2022 05:25:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-string-of-words-into-a-new-variable/m-p/841258#M332633</guid>
      <dc:creator>Jedrzej</dc:creator>
      <dc:date>2022-10-28T05:25:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract string of words into a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-string-of-words-into-a-new-variable/m-p/841266#M332636</link>
      <description>&lt;P&gt;Is&amp;nbsp;&lt;SPAN&gt;a´defunct 1 or 2 words in this case?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2022 07:56:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-string-of-words-into-a-new-variable/m-p/841266#M332636</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-10-28T07:56:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract string of words into a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-string-of-words-into-a-new-variable/m-p/841267#M332637</link>
      <description>one, sorry mistype</description>
      <pubDate>Fri, 28 Oct 2022 07:57:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-string-of-words-into-a-new-variable/m-p/841267#M332637</guid>
      <dc:creator>Jedrzej</dc:creator>
      <dc:date>2022-10-28T07:57:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract string of words into a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-string-of-words-into-a-new-variable/m-p/841268#M332638</link>
      <description>&lt;P&gt;Ok. How about&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover;
input str $char150.;
cards;
New Year Copenhagen is the Capital of Denmark Jensen is a´defunct British manufacturer of sports cars Another line Paris is a capital of France
;
run;

data temp(keep = g s);
   set have;
   length s $200;
   do i = 1 to countw(str);
      s = catx(' ', s, scan(str, i));
      if countw(s)= 10 | i = countw(str) then do;
         g + 1;
         output;
         s = '';
      end;
   end;
run;

proc transpose data = temp out = want(drop = _:) prefix = str;
   id g;
   var s;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Result:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;str1                    str2             str3
New Year Copenhagen...  is a´defunct...  is a capital of France&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2022 08:01:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-string-of-words-into-a-new-variable/m-p/841268#M332638</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-10-28T08:01:52Z</dc:date>
    </item>
  </channel>
</rss>

