<?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: Counting the number of phrases in a string? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-phrases-in-a-string/m-p/656553#M196876</link>
    <description>&lt;P&gt;You can specify the delimiter in COUNTW.&amp;nbsp; I do that a lot in examples like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let x=1,2,3,4;

%do i = 1 %to %sysfunc(countw(%superq(x),%str(,)));
    %put %scan(%superq(x),&amp;amp;i,%str(,));
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;%superq above just masks things like commas, quotes etc.&amp;nbsp; When using commas as the delimiter though in a macro %sysfunc make sure you wrap it with %str to tell SAS it's a macro text string and not separating options.&amp;nbsp; If in a data step then you would do COUNTW(x,',') if you are using a comma as the delimiter.&lt;/P&gt;</description>
    <pubDate>Wed, 10 Jun 2020 20:32:13 GMT</pubDate>
    <dc:creator>JeffMeyers</dc:creator>
    <dc:date>2020-06-10T20:32:13Z</dc:date>
    <item>
      <title>Counting the number of phrases in a string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-phrases-in-a-string/m-p/656551#M196874</link>
      <description>&lt;P&gt;I have a list such as:&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%LET FILELIST= First File Name, Filename Number Two, The Third One, File Number IV, Five Is The Last One;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to count the number of phrases? More specifically is there a way to get CountW to not register a space as a delimiter, and only register a specified delimiter?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I currently have a code working properly but only with a / as a delimiter.&amp;nbsp; Where i manually changed all commas to / and count the number of / and add 1.&amp;nbsp;&lt;/P&gt;&lt;P&gt;such as:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%LET FILELIST= First File Name/ Filename Number Two/ The Third One/ File Number IV/ Five Is The Last One;&lt;/P&gt;&lt;P&gt;%MACRO LOOP_F();&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;%DO F=1 %TO %SYSFUNC(Count(&amp;amp;FILELIST.,/))+1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %LET FF=%SCAN(&amp;amp;FILELIST.,&amp;amp;F.,/ );&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %IMPORT_TM(&amp;amp;FF.);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;%END;&lt;BR /&gt;%MEND LOOP_F;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;where Import_TM is another macro.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can i count the number of phrases directly, without resorting to counting delimiters and adding 1?&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jun 2020 20:26:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-phrases-in-a-string/m-p/656551#M196874</guid>
      <dc:creator>mcook</dc:creator>
      <dc:date>2020-06-10T20:26:28Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of phrases in a string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-phrases-in-a-string/m-p/656553#M196876</link>
      <description>&lt;P&gt;You can specify the delimiter in COUNTW.&amp;nbsp; I do that a lot in examples like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let x=1,2,3,4;

%do i = 1 %to %sysfunc(countw(%superq(x),%str(,)));
    %put %scan(%superq(x),&amp;amp;i,%str(,));
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;%superq above just masks things like commas, quotes etc.&amp;nbsp; When using commas as the delimiter though in a macro %sysfunc make sure you wrap it with %str to tell SAS it's a macro text string and not separating options.&amp;nbsp; If in a data step then you would do COUNTW(x,',') if you are using a comma as the delimiter.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jun 2020 20:32:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-phrases-in-a-string/m-p/656553#M196876</guid>
      <dc:creator>JeffMeyers</dc:creator>
      <dc:date>2020-06-10T20:32:13Z</dc:date>
    </item>
  </channel>
</rss>

