<?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: COUNTW in a macro with incorrect word counts in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/COUNTW-in-a-macro-with-incorrect-word-counts/m-p/424662#M104573</link>
    <description>&lt;P&gt;Wow,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;, I did not know that. That is a very easy solution!&lt;/P&gt;</description>
    <pubDate>Wed, 03 Jan 2018 18:42:20 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2018-01-03T18:42:20Z</dc:date>
    <item>
      <title>COUNTW in a macro with incorrect word counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/COUNTW-in-a-macro-with-incorrect-word-counts/m-p/424647#M104568</link>
      <description>&lt;P&gt;&lt;FONT face="arial black,avant garde"&gt;Hi,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial black,avant garde"&gt;Does anyone know if "countw" can skip the space between single quoted words?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial black,avant garde"&gt;&lt;U&gt;Here is my code:&lt;/U&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt; colnames1(colnames1);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put "number of names in columns is " %sysfunc(countw(&amp;amp;colnames1));&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt; colnames1;&lt;/P&gt;&lt;P&gt;%&lt;STRONG&gt;&lt;EM&gt;colnames1&lt;/EM&gt;&lt;/STRONG&gt;(Contracts age 'young boys'n 'young girls'n);&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial black,avant garde"&gt;&lt;U&gt;The result is:&lt;/U&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro colnames1(colnames1);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put "number of names in columns is " %sysfunc(countw(&amp;amp;colnames1));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %mend colnames1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %colnames1(Contracts age 'young boys'n 'young girls'n);&lt;/P&gt;&lt;P&gt;"number of names in columns is " 6&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial black,avant garde"&gt;&lt;U&gt;There should only be 4 words ('contracts', 'age', 'young boys' and 'young girls'). The program is counting the spaces&amp;nbsp;in between the single quotes.&lt;/U&gt; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial black,avant garde"&gt;&lt;U&gt;I further tried to following but still didn't get the results I wanted (still gave me 6 words).&lt;/U&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%put "number of names in columns is " %sysfunc(countw(&amp;amp;colnames2%str("")));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial black,avant garde"&gt;THANKS!&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 18:13:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/COUNTW-in-a-macro-with-incorrect-word-counts/m-p/424647#M104568</guid>
      <dc:creator>LuLuVolcano73</dc:creator>
      <dc:date>2018-01-03T18:13:14Z</dc:date>
    </item>
    <item>
      <title>Re: COUNTW in a macro with incorrect word counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/COUNTW-in-a-macro-with-incorrect-word-counts/m-p/424651#M104569</link>
      <description>&lt;P&gt;One reason you shouldn't use named literals but oh well.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An easy fix would be to add a delimiter to the words and count that instead, ie&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%&lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM&gt;colnames1&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN&gt;(Contracts | age |&amp;nbsp; 'young boys'n | 'young girls'n);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Use COUNTC to count the number of | and then add one to determine the number of 'variables'.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 18:17:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/COUNTW-in-a-macro-with-incorrect-word-counts/m-p/424651#M104569</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-03T18:17:35Z</dc:date>
    </item>
    <item>
      <title>Re: COUNTW in a macro with incorrect word counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/COUNTW-in-a-macro-with-incorrect-word-counts/m-p/424655#M104570</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/184198"&gt;@LuLuVolcano73&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&lt;FONT face="arial black,avant garde"&gt;Hi,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial black,avant garde"&gt;Does anyone know if "countw" can skip the space between single quoted words?&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial black,avant garde"&gt;&lt;U&gt;Here is my code:&lt;/U&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt; colnames1(colnames1);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put "number of names in columns is " %sysfunc(countw(&amp;amp;colnames1));&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt; colnames1;&lt;/P&gt;
&lt;P&gt;%&lt;STRONG&gt;&lt;EM&gt;colnames1&lt;/EM&gt;&lt;/STRONG&gt;(Contracts age 'young boys'n 'young girls'n);&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial black,avant garde"&gt;&lt;U&gt;The result is:&lt;/U&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro colnames1(colnames1);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put "number of names in columns is " %sysfunc(countw(&amp;amp;colnames1));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %mend colnames1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %colnames1(Contracts age 'young boys'n 'young girls'n);&lt;/P&gt;
&lt;P&gt;"number of names in columns is " 6&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial black,avant garde"&gt;&lt;U&gt;There should only be 4 words ('contracts', 'age', 'young boys' and 'young girls'). The program is counting the spaces&amp;nbsp;in between the single quotes.&lt;/U&gt; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial black,avant garde"&gt;&lt;U&gt;I further tried to following but still didn't get the results I wanted (still gave me 6 words).&lt;/U&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%put "number of names in columns is " %sysfunc(countw(&amp;amp;colnames2%str("")));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial black,avant garde"&gt;THANKS!&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That run; statement doesn't belong ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;however, COUNTW is doing the proper thing here, it just sees colnames as a text string, it doesn't understand that you think 'young boys'n is one word. it is simply looking for the space to delimit the words, and so 'young boys'n is two words, the first being 'young and the second being boys'n.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you really want this to be 4 words, you would need some other approach, I don't think COUNTW can get there. Perhaps using regular expressions can turn 'young boys'n into young_boys which then is counted properly by COUNTW.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or, you can put the anti-delimiters in manually, replacing 'young boys'n with young_boys and 'young girls'n with young_girls. And also in this case COUNTW will work as expected.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 18:37:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/COUNTW-in-a-macro-with-incorrect-word-counts/m-p/424655#M104570</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-01-03T18:37:41Z</dc:date>
    </item>
    <item>
      <title>Re: COUNTW in a macro with incorrect word counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/COUNTW-in-a-macro-with-incorrect-word-counts/m-p/424658#M104571</link>
      <description>&lt;P&gt;Try&lt;/P&gt;
&lt;PRE&gt;%macro colnames1(colnames1);

     %put "number of names in columns is " %sysfunc(countw(&amp;amp;colnames1," " ,Q ));

%mend colnames1;&lt;/PRE&gt;
&lt;P&gt;The Q says to ignore delimiters within quotes,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 18:31:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/COUNTW-in-a-macro-with-incorrect-word-counts/m-p/424658#M104571</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-01-03T18:31:40Z</dc:date>
    </item>
    <item>
      <title>Re: COUNTW in a macro with incorrect word counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/COUNTW-in-a-macro-with-incorrect-word-counts/m-p/424661#M104572</link>
      <description>&lt;P&gt;Thank you! You are AWESOME!&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 18:41:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/COUNTW-in-a-macro-with-incorrect-word-counts/m-p/424661#M104572</guid>
      <dc:creator>LuLuVolcano73</dc:creator>
      <dc:date>2018-01-03T18:41:27Z</dc:date>
    </item>
    <item>
      <title>Re: COUNTW in a macro with incorrect word counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/COUNTW-in-a-macro-with-incorrect-word-counts/m-p/424662#M104573</link>
      <description>&lt;P&gt;Wow,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;, I did not know that. That is a very easy solution!&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 18:42:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/COUNTW-in-a-macro-with-incorrect-word-counts/m-p/424662#M104573</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-01-03T18:42:20Z</dc:date>
    </item>
    <item>
      <title>Re: COUNTW in a macro with incorrect word counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/COUNTW-in-a-macro-with-incorrect-word-counts/m-p/424663#M104574</link>
      <description>&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 18:43:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/COUNTW-in-a-macro-with-incorrect-word-counts/m-p/424663#M104574</guid>
      <dc:creator>LuLuVolcano73</dc:creator>
      <dc:date>2018-01-03T18:43:08Z</dc:date>
    </item>
  </channel>
</rss>

