<?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: Extract words from macro variable in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Extract-words-from-macro-variable/m-p/230166#M5638</link>
    <description>&lt;P&gt;Can you guarantee that the same word will never appear twice within the list?&amp;nbsp; That could impact what tools will work.&lt;/P&gt;</description>
    <pubDate>Thu, 15 Oct 2015 20:40:28 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2015-10-15T20:40:28Z</dc:date>
    <item>
      <title>Extract words from macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Extract-words-from-macro-variable/m-p/230159#M5636</link>
      <description>&lt;P&gt;Is there a way we can extract number of words from a macro variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example :&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;%let var = Balance Years_Since_Active Field1 Field2;&lt;/P&gt;
&lt;P&gt;I want to extract first 3 from this list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note : In reality, the list is really big. It contains almost 800 words. I wanted to extract first 100 words. After that, I would like to extract from 101 to 200 and so on. Hence, the solution should be dynamic in such a manner user can specify lower limit i.e. 1 and upper limit i.e. 100.&amp;nbsp;= SCAN(&amp;amp;var, (1:100), ' ').&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2015 20:09:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Extract-words-from-macro-variable/m-p/230159#M5636</guid>
      <dc:creator>Ujjawal</dc:creator>
      <dc:date>2015-10-15T20:09:53Z</dc:date>
    </item>
    <item>
      <title>Re: Extract words from macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Extract-words-from-macro-variable/m-p/230163#M5637</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let var = Balance Years_Since_Active Field1 Field2;
%let word_count = %sysfunc(countw(&amp;amp;var));
%put word_count = &amp;amp;word_count;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Oct 2015 20:20:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Extract-words-from-macro-variable/m-p/230163#M5637</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2015-10-15T20:20:07Z</dc:date>
    </item>
    <item>
      <title>Re: Extract words from macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Extract-words-from-macro-variable/m-p/230166#M5638</link>
      <description>&lt;P&gt;Can you guarantee that the same word will never appear twice within the list?&amp;nbsp; That could impact what tools will work.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2015 20:40:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Extract-words-from-macro-variable/m-p/230166#M5638</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-10-15T20:40:28Z</dc:date>
    </item>
    <item>
      <title>Re: Extract words from macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Extract-words-from-macro-variable/m-p/230176#M5639</link>
      <description>&lt;P&gt;Yes the same word will&amp;nbsp;never come twice within the list.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2015 21:18:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Extract-words-from-macro-variable/m-p/230176#M5639</guid>
      <dc:creator>Ujjawal</dc:creator>
      <dc:date>2015-10-15T21:18:06Z</dc:date>
    </item>
    <item>
      <title>Re: Extract words from macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Extract-words-from-macro-variable/m-p/230198#M5643</link>
      <description>&lt;P&gt;Given that the same word never appears twice ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's probably a little easier to work with a DATA step instead of macro language. &amp;nbsp;But all of this logic could be done with a macro if necessary.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let first_word = 5;&lt;/P&gt;
&lt;P&gt;%let last_word = 10;&lt;/P&gt;
&lt;P&gt;%let var = some list of a great many words that do not contain any repeats;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;/P&gt;
&lt;P&gt;p1 = scan("&amp;amp;var", &amp;amp;first_word, ' ');&lt;/P&gt;
&lt;P&gt;p2 = scan("&amp;amp;var", &amp;amp;last_word, ' ');&lt;/P&gt;
&lt;P&gt;if p1 &amp;gt; ' ' and p2 &amp;gt; ' ';&lt;/P&gt;
&lt;P&gt;position1 = findw("&amp;amp;var", strip(p1));&lt;/P&gt;
&lt;P&gt;position2 =&amp;nbsp;findw("&amp;amp;var", strip(p2));&lt;/P&gt;
&lt;P&gt;subset_of_words = substr("&amp;amp;var", position1, position2 - position1 + length(p2));&lt;/P&gt;
&lt;P&gt;call symputx('subset_of_words', subset_of_words);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;subset_of_words;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's untested code, but should be fine. &amp;nbsp;At least the number of tools used is fairly small if you need to review any of them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2015 23:47:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Extract-words-from-macro-variable/m-p/230198#M5643</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-10-15T23:47:38Z</dc:date>
    </item>
    <item>
      <title>Re: Extract words from macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Extract-words-from-macro-variable/m-p/230225#M5645</link>
      <description>It's possibly more efficient to toss the list into a data step and then query it via either a data step or proc sql.  At least it might be easier to understand &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Fri, 16 Oct 2015 04:37:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Extract-words-from-macro-variable/m-p/230225#M5645</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-10-16T04:37:50Z</dc:date>
    </item>
  </channel>
</rss>

