<?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: Count number words in macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Count-number-words-in-macro-variable/m-p/583302#M166048</link>
    <description>&lt;P&gt;I point out that there's almost never a need to have macro variable values with quotes around them, and its just not a good idea. (What would you do with some of these macro variable words that have quotes around them and others that do not?)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A better idea would be to have macro variable values without the quotes around them, and a delimiter of some special character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro do_all;
%let varlist = Word One~Word2~Word Three;

%do i=1 %to %sysfunc(countw(&amp;amp;varlist,~));
    %let term=%scan(&amp;amp;varlist,&amp;amp;i,~);
    %put &amp;amp;=term;
%end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 22 Aug 2019 18:57:37 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2019-08-22T18:57:37Z</dc:date>
    <item>
      <title>Count number words in macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-number-words-in-macro-variable/m-p/583292#M166045</link>
      <description>&lt;P&gt;Suppose my macro variable contain three words : "Word One"&amp;nbsp; Word2&amp;nbsp; "Word Three";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%varlist =&amp;nbsp;"Word One"&amp;nbsp; Word2&amp;nbsp; "Word Three";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro do_all;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %do i=1 %to %sysfunc(countw(&amp;amp;varlist ));&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %let term=%scan(&amp;amp;varlist, &amp;amp;i);&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %put &amp;amp;term;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My problem that some variable names consist of two words that separated by blank and this code doesn't work.&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My problem, that some variable names consist of two words that separated by blank.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2019 18:27:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-number-words-in-macro-variable/m-p/583292#M166045</guid>
      <dc:creator>AlexeyS</dc:creator>
      <dc:date>2019-08-22T18:27:00Z</dc:date>
    </item>
    <item>
      <title>Re: Count number words in macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-number-words-in-macro-variable/m-p/583299#M166047</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/42503"&gt;@AlexeyS&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use the "q" modifier of both the COUNTW function and the %SCAN function to ignore the blanks inside quotation marks:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro do_all;
%do i=1 %to %sysfunc(countw(&amp;amp;varlist, %str( ), q));
  %let term=%scan(&amp;amp;varlist, &amp;amp;i, %str( ), q);
  %put &amp;amp;term;
%end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Aug 2019 18:40:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-number-words-in-macro-variable/m-p/583299#M166047</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-08-22T18:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: Count number words in macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-number-words-in-macro-variable/m-p/583302#M166048</link>
      <description>&lt;P&gt;I point out that there's almost never a need to have macro variable values with quotes around them, and its just not a good idea. (What would you do with some of these macro variable words that have quotes around them and others that do not?)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A better idea would be to have macro variable values without the quotes around them, and a delimiter of some special character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro do_all;
%let varlist = Word One~Word2~Word Three;

%do i=1 %to %sysfunc(countw(&amp;amp;varlist,~));
    %let term=%scan(&amp;amp;varlist,&amp;amp;i,~);
    %put &amp;amp;=term;
%end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2019 18:57:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-number-words-in-macro-variable/m-p/583302#M166048</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-08-22T18:57:37Z</dc:date>
    </item>
  </channel>
</rss>

