<?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 Parse text data into individual words in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Parse-text-data-into-individual-words/m-p/170999#M32834</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi SAS community pros!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to create a data step and/or macro that will parse a large amount of text into individual words for further analysis. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to give SAS a data set with text strings in one variable, and have it return one new variable with all the words from the input variable as separate observations and removing common (or specified list of) delimiters.&lt;/P&gt;&lt;P&gt;I have been experimenting with the SCAN function, but have not had training in how to execute loops or macro array variables. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example, please see the below excel screenshot for a simplistic example.&amp;nbsp; Would like to start with SAS data set column A only, and return SAS data set columns A and B&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your assistance!&lt;/P&gt;&lt;P&gt;&lt;IMG alt="parse.png" class="jive-image" src="https://communities.sas.com/legacyfs/online/7882_parse.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 13 Nov 2014 22:57:16 GMT</pubDate>
    <dc:creator>crosskonaftw</dc:creator>
    <dc:date>2014-11-13T22:57:16Z</dc:date>
    <item>
      <title>Parse text data into individual words</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-text-data-into-individual-words/m-p/170999#M32834</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi SAS community pros!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to create a data step and/or macro that will parse a large amount of text into individual words for further analysis. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to give SAS a data set with text strings in one variable, and have it return one new variable with all the words from the input variable as separate observations and removing common (or specified list of) delimiters.&lt;/P&gt;&lt;P&gt;I have been experimenting with the SCAN function, but have not had training in how to execute loops or macro array variables. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example, please see the below excel screenshot for a simplistic example.&amp;nbsp; Would like to start with SAS data set column A only, and return SAS data set columns A and B&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your assistance!&lt;/P&gt;&lt;P&gt;&lt;IMG alt="parse.png" class="jive-image" src="https://communities.sas.com/legacyfs/online/7882_parse.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Nov 2014 22:57:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-text-data-into-individual-words/m-p/170999#M32834</guid>
      <dc:creator>crosskonaftw</dc:creator>
      <dc:date>2014-11-13T22:57:16Z</dc:date>
    </item>
    <item>
      <title>Re: Parse text data into individual words</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-text-data-into-individual-words/m-p/171000#M32835</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This may get you started. This will duplicate the string. COUNTW and SCAN have a large number of possible combinations of delimiters.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; string = 'For example, please see the below excel screenshot for a simplistic example.';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; words = countw(string,'sp');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do i=1 to words;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; word = scan(string,i,'sp');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; drop i words;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Nov 2014 23:09:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-text-data-into-individual-words/m-p/171000#M32835</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2014-11-13T23:09:07Z</dc:date>
    </item>
    <item>
      <title>Re: Parse text data into individual words</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-text-data-into-individual-words/m-p/171001#M32836</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not quite what you asked for, but I'm not sure having the A column as you requested would be useful either. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;a="Wolf, meeting with a Lamb astray from the fold,";output;&lt;/P&gt;&lt;P&gt;a="resolved not to lay violent hands on him"; output;&lt;/P&gt;&lt;P&gt;a="but to find some plea"; output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; i=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do while (scan(a, i) ne "");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b=scan(a,i);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Nov 2014 23:10:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-text-data-into-individual-words/m-p/171001#M32836</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-11-13T23:10:20Z</dc:date>
    </item>
    <item>
      <title>Re: Parse text data into individual words</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-text-data-into-individual-words/m-p/171002#M32837</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Based on Reeza solution, how about:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;a="Wolf, meeting with a Lamb astray from the fold,"; &lt;STRONG&gt;n+1;&lt;/STRONG&gt; output;&lt;/P&gt;&lt;P&gt;a="resolved not to lay violent hands on him"; &lt;STRONG&gt;n+1;&lt;/STRONG&gt; output;&lt;/P&gt;&lt;P&gt;a="but to find some plea"; &lt;STRONG&gt;n+1;&lt;/STRONG&gt; output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data&lt;STRONG&gt; temp(keep=b j);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; i=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do while (scan(a, i) ne "");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b=scan(a,i);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt; j+1;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sql noprint;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; create table want (drop=j) as&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; select a,b,j&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; from have right join temp&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; on n=j&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; order by j;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CTorres&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Nov 2014 18:40:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-text-data-into-individual-words/m-p/171002#M32837</guid>
      <dc:creator>CTorres</dc:creator>
      <dc:date>2014-11-14T18:40:47Z</dc:date>
    </item>
    <item>
      <title>Re: Parse text data into individual words</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-text-data-into-individual-words/m-p/171003#M32838</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you all for your input!&amp;nbsp; Apologies for the delayed response as I have been sick and travelling. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am going to use all of your suggestions as a working starting template and improve upon it.&amp;nbsp; Thanks again!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Nov 2014 08:28:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-text-data-into-individual-words/m-p/171003#M32838</guid>
      <dc:creator>crosskonaftw</dc:creator>
      <dc:date>2014-11-24T08:28:14Z</dc:date>
    </item>
    <item>
      <title>Re: Parse text data into individual words</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-text-data-into-individual-words/m-p/257658#M49481</link>
      <description>&lt;P&gt;Great question, I needed this exact answer today!&lt;/P&gt;</description>
      <pubDate>Fri, 18 Mar 2016 16:26:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-text-data-into-individual-words/m-p/257658#M49481</guid>
      <dc:creator>kjohnsonm</dc:creator>
      <dc:date>2016-03-18T16:26:47Z</dc:date>
    </item>
  </channel>
</rss>

