<?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 Count words in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Count-words/m-p/753521#M237506</link>
    <description>&lt;P&gt;Please help me to solve this query:&lt;/P&gt;
&lt;P&gt;I have one string as below :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Name = "Is this the real life? Is this just fantasy? Caught in a landslide. No escape from reality!" ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to do these things :-&lt;/P&gt;
&lt;P&gt;1.&amp;nbsp;&lt;STRONG&gt;Count the number of words (character strings) separated by blanks in Name1&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;2.&amp;nbsp; Also I need to get these values too using Name string in a new dataset Name2&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Num&amp;nbsp; &amp;nbsp;word&lt;/STRONG&gt;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;Is this the real life&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;Is this just fantasy&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;Caught in a landslide&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;4&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;No escape from reality&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;5&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 12 Jul 2021 15:14:25 GMT</pubDate>
    <dc:creator>Aexor</dc:creator>
    <dc:date>2021-07-12T15:14:25Z</dc:date>
    <item>
      <title>Count words</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-words/m-p/753521#M237506</link>
      <description>&lt;P&gt;Please help me to solve this query:&lt;/P&gt;
&lt;P&gt;I have one string as below :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Name = "Is this the real life? Is this just fantasy? Caught in a landslide. No escape from reality!" ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to do these things :-&lt;/P&gt;
&lt;P&gt;1.&amp;nbsp;&lt;STRONG&gt;Count the number of words (character strings) separated by blanks in Name1&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;2.&amp;nbsp; Also I need to get these values too using Name string in a new dataset Name2&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Num&amp;nbsp; &amp;nbsp;word&lt;/STRONG&gt;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;Is this the real life&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;Is this just fantasy&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;Caught in a landslide&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;4&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;No escape from reality&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;5&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jul 2021 15:14:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-words/m-p/753521#M237506</guid>
      <dc:creator>Aexor</dc:creator>
      <dc:date>2021-07-12T15:14:25Z</dc:date>
    </item>
    <item>
      <title>Re: Count words</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-words/m-p/753523#M237508</link>
      <description>&lt;P&gt;Just use COUNTW() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input num word $60.;
cards;
1 Is this the real life
2 Is this just fantasy
3 Caught in a landslide
4 No escape from reality
5
;

data want;
  set have;
  nwords=countw(word,' ');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;Obs    num             word             nwords

 1      1     Is this the real life        5
 2      2     Is this just fantasy         4
 3      3     Caught in a landslide        4
 4      4     No escape from reality       4
 5      5                                  0

&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Jul 2021 15:17:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-words/m-p/753523#M237508</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-07-12T15:17:50Z</dc:date>
    </item>
    <item>
      <title>Re: Count words</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-words/m-p/753542#M237521</link>
      <description>I need to use This string and get values of Num and Word&lt;BR /&gt;&lt;BR /&gt;Name = "Is this the real life? Is this just fantasy? Caught in a landslide. No escape from reality!" ;</description>
      <pubDate>Mon, 12 Jul 2021 15:59:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-words/m-p/753542#M237521</guid>
      <dc:creator>Aexor</dc:creator>
      <dc:date>2021-07-12T15:59:09Z</dc:date>
    </item>
    <item>
      <title>Re: Count words</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-words/m-p/753558#M237530</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/327170"&gt;@Aexor&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I need to use This string and get values of Num and Word&lt;BR /&gt;&lt;BR /&gt;Name = "Is this the real life? Is this just fantasy? Caught in a landslide. No escape from reality!" ;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;How does &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; 's code not work? Explicit descriptions are needed.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jul 2021 17:21:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-words/m-p/753558#M237530</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-07-12T17:21:09Z</dc:date>
    </item>
    <item>
      <title>Re: Count words</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-words/m-p/753563#M237533</link>
      <description>This is not matching with my requirement .&lt;BR /&gt;In my requirement I have only a string Name which is having value as "Is this the real life? Is this just fantasy? Caught in a landslide. No escape from reality!" ;&lt;BR /&gt;data have ;&lt;BR /&gt;Input Name $ ;&lt;BR /&gt;Name =   "Is this the real life? Is this just fantasy? Caught in a landslide. No escape from reality!" ;&lt;BR /&gt;run;&lt;BR /&gt;1.  The first requirement is Count the number of words (character strings) separated by blanks in  new variable Name1&lt;BR /&gt;&lt;BR /&gt;2.  The second requirement is &lt;BR /&gt;I have to create a dataset (NAME2 ) using dataset have where I can separate out each string delimited with "? or . or ! "  and also add sequence number so my output will look like this &lt;BR /&gt;&lt;BR /&gt;data Want&lt;BR /&gt;NUM	Word&lt;BR /&gt;1	Is this the real life&lt;BR /&gt;2	Is this just fantasy&lt;BR /&gt;3	Caught in a landslide&lt;BR /&gt;4	No escape from reality&lt;BR /&gt;5	 &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I hope I am making some sense here &lt;BR /&gt;</description>
      <pubDate>Mon, 12 Jul 2021 17:38:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-words/m-p/753563#M237533</guid>
      <dc:creator>Aexor</dc:creator>
      <dc:date>2021-07-12T17:38:34Z</dc:date>
    </item>
    <item>
      <title>Re: Count words</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-words/m-p/753589#M237547</link>
      <description>&lt;P&gt;First, test data step code. Your input means name will have a total of 8 characters maximum depending on the length of the first "word".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second, you haven't shown what you expect the FIRST output to actually look like.&lt;/P&gt;
&lt;PRE&gt;data junk;
   Name = "Is this the real life? Is this just fantasy? Caught in a landslide. No escape from reality!" ;
run;

data want1;
   set junk;
   wordcount = countw(name,' ');
run;

data want2;
   set junk;
   do i=1 to countw(name,'.?!');
      word = scan(name,i, '.?!');
      countwd= countw(word);
      output;
   end;
   drop name;
run;&lt;/PRE&gt;
&lt;P&gt;If you need other delimiters such ;:@#$^&amp;amp;* or what have you they can go in the SCAN third position as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jul 2021 20:10:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-words/m-p/753589#M237547</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-07-12T20:10:08Z</dc:date>
    </item>
    <item>
      <title>Re: Count words</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-words/m-p/753608#M237551</link>
      <description>&lt;P&gt;You seem to have skipped the first step.&amp;nbsp;How to you intend to get from your starting data of one long string into your original posted data of four separate strings?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
  paragraph="Is this the real life? Is this just fantasy? Caught in a landslide. No escape from reality!" ;
  do snum=1 to countw(paragraph,'?.!');
    sentence=scan(paragraph,snum,'?.!');
    nwords=countw(sentence,' ');
    output;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/61147i0655452EC747ABE4/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jul 2021 20:15:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-words/m-p/753608#M237551</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-07-12T20:15:05Z</dc:date>
    </item>
  </channel>
</rss>

