<?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 n and d Modifier in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Countw-n-and-d-Modifier/m-p/634113#M188197</link>
    <description>&lt;P&gt;I think the questions you have are actually basic ones:&amp;nbsp; What is a word?&amp;nbsp; What is a delimiter?&amp;nbsp; The answers affect how COUNTW counts, and the number of words that it finds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, in the data lines that you illustrated, should "+" be a delimiter, or should it be a character within a word?&amp;nbsp; By default, it is a character within a word.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming you are working on an ASCII-based system, these characters are delimiters rather than part of a word:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;blank ! $ % &amp;amp; ( ) * + , - . / ; &amp;lt; ^ |&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You have control over that, however.&amp;nbsp; Using the "n" or "d" modifiers (and there are additional choices as well) switches the meaning of some characters.&amp;nbsp; They now become delimiters, rather than being characters within a word.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 23 Mar 2020 13:58:38 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2020-03-23T13:58:38Z</dc:date>
    <item>
      <title>Countw n and d Modifier</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Countw-n-and-d-Modifier/m-p/634043#M188155</link>
      <description>&lt;P&gt;Hi everybody. I'm confused with the n and d delimiter in Countw funtion. Would someone explain a little bit? Any thoughts would be appreciated!&lt;BR /&gt;For countw function,&amp;nbsp;&lt;BR /&gt;1. d or D adds digits to the list of characters.&amp;nbsp;&lt;BR /&gt;2. n or N adds digits, an underscore, and English letters(that is, the characters that can appear after the first characterin a SAS variable name using VALIDVARNAME=V7) to the list of characters.&amp;nbsp;Thus, for the code below,I think the result should be:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;obs&amp;nbsp; &amp;nbsp; n&amp;nbsp; &amp;nbsp; d&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;1&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; 4&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;2&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; 5&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
	input string $char60.;
	datalines;
'_'2+2=4
\\"Windows"  "\Path\Names\Use\Backslashes
;
run;
data test1;
    set test;
	d=countw(string,,'d');
	n=countw(string,,'n');
run;
proc print data=test1;run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However，the result is different, as shown in the picture below.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Mar 2020 05:43:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Countw-n-and-d-Modifier/m-p/634043#M188155</guid>
      <dc:creator>Cecillia_Mao</dc:creator>
      <dc:date>2020-03-23T05:43:31Z</dc:date>
    </item>
    <item>
      <title>Re: Countw n and d Modifier</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Countw-n-and-d-Modifier/m-p/634089#M188179</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Remember that character variables are padded with trailing blanks. When you specify the delimiters and do not include a blank as a delimiter, the trailing blanks counts as a word.&amp;nbsp; You can use the TRIMN function to remove trailing blanks.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below log shows the result you expect:&lt;/P&gt;
&lt;PRE&gt;26   data test1;
27       set test;
28     d=countw(trimn(string),,'d');
29     n=countw(trimn(string),,'n');
30
31     put (string d n)(=) ;
32   run;

string='_'2+2=4 d=3 n=4
string=\\"Windows"  "\Path\Names\Use\Backslashes d=1 n=5
&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Mar 2020 12:59:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Countw-n-and-d-Modifier/m-p/634089#M188179</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2020-03-23T12:59:14Z</dc:date>
    </item>
    <item>
      <title>Re: Countw n and d Modifier</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Countw-n-and-d-Modifier/m-p/634113#M188197</link>
      <description>&lt;P&gt;I think the questions you have are actually basic ones:&amp;nbsp; What is a word?&amp;nbsp; What is a delimiter?&amp;nbsp; The answers affect how COUNTW counts, and the number of words that it finds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, in the data lines that you illustrated, should "+" be a delimiter, or should it be a character within a word?&amp;nbsp; By default, it is a character within a word.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming you are working on an ASCII-based system, these characters are delimiters rather than part of a word:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;blank ! $ % &amp;amp; ( ) * + , - . / ; &amp;lt; ^ |&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You have control over that, however.&amp;nbsp; Using the "n" or "d" modifiers (and there are additional choices as well) switches the meaning of some characters.&amp;nbsp; They now become delimiters, rather than being characters within a word.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Mar 2020 13:58:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Countw-n-and-d-Modifier/m-p/634113#M188197</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-03-23T13:58:38Z</dc:date>
    </item>
    <item>
      <title>Re: Countw n and d Modifier</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Countw-n-and-d-Modifier/m-p/634153#M188216</link>
      <description>Dear Quentin, that totally makes sense! Thanks so much! But I do not quite understand why the variable value with the showest length (in this case would be string 1) will also be padded with a trailing space?</description>
      <pubDate>Mon, 23 Mar 2020 15:46:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Countw-n-and-d-Modifier/m-p/634153#M188216</guid>
      <dc:creator>Cecillia_Mao</dc:creator>
      <dc:date>2020-03-23T15:46:24Z</dc:date>
    </item>
    <item>
      <title>Re: Countw n and d Modifier</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Countw-n-and-d-Modifier/m-p/634154#M188217</link>
      <description>Dear Astounding, thanks so much for your reply! Based on my understanding, ‘+’ is one of default delimiter on the ASCII-based system, but if I specified a specific delimiter(Let's say d or D adds digits to the list of characters in this case) then it will override the default, and '+' would be a word. Please free me to correct me if I understand wrong.&lt;BR /&gt;</description>
      <pubDate>Mon, 23 Mar 2020 15:49:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Countw-n-and-d-Modifier/m-p/634154#M188217</guid>
      <dc:creator>Cecillia_Mao</dc:creator>
      <dc:date>2020-03-23T15:49:37Z</dc:date>
    </item>
    <item>
      <title>Re: Countw n and d Modifier</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Countw-n-and-d-Modifier/m-p/634168#M188221</link>
      <description>&lt;P&gt;You're getting closer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Adding "n" or "d" does not change the default set of delimiters.&amp;nbsp; It modifies the default set by adding characters that also function as delimiters.&amp;nbsp; So "+" remains a delimiter when you add "n" or "d".&amp;nbsp; If you want to replace the default set of delimiters, you can do that.&amp;nbsp; You would need to add the delimiters that you want as the second parameter, between what is now the two consecutive commas.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Mar 2020 16:44:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Countw-n-and-d-Modifier/m-p/634168#M188221</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-03-23T16:44:58Z</dc:date>
    </item>
    <item>
      <title>Re: Countw n and d Modifier</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Countw-n-and-d-Modifier/m-p/634179#M188225</link>
      <description>&lt;P&gt;When you read the data into SAS, you specified that the variable STRING was 60 characters long. So if the value assigned to string is less than 60 characters long, it will be padded with blanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have a variable that is one character long, and you put one character in it, it is not padded with blanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below example shows String1 has a length of one character, and String2 has a length of two characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
	input string1 : $1. string2 : $2.;
	datalines;
A 1
1 11
;
run; 
data test1;
  set test;
	d1=countw(string1,,'d');
  d2=countw(string2,,'d');
  put string1= d1= string2= d2=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Mar 2020 17:22:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Countw-n-and-d-Modifier/m-p/634179#M188225</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2020-03-23T17:22:11Z</dc:date>
    </item>
    <item>
      <title>Re: Countw n and d Modifier</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Countw-n-and-d-Modifier/m-p/634257#M188244</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/275960"&gt;@Cecillia_Mao&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think the default delimiters are not applied if more than one argument is used (see&amp;nbsp;&lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p18xi2516ihygyn1qg1b1nby326k.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank" rel="noopener"&gt;documentation&lt;/A&gt;). This includes the case of an empty second argument as in your examples (or in&amp;nbsp;&lt;FONT face="courier new,courier"&gt;countw(string,,)&lt;/FONT&gt;where also the third argument is empty or in &amp;nbsp;&lt;FONT face="courier new,courier"&gt;countw(string,)&lt;/FONT&gt;&amp;nbsp;where the third argument is not used). That is, with two or three arguments (empty or not) the list of delimiters is constructed from the second argument and, if applicable, modified by the third argument. In particular, an empty second argument means an empty list of delimiters (i.e. &lt;EM&gt;no&lt;/EM&gt; character serves as a delimiter), until the modification by the third argument is applied, if any. So, in your examples the digits ('d') or "name characters" ('n'), respectively, are added to the empty list (&lt;EM&gt;not&lt;/EM&gt; to the list of default delimiters), i.e., they are eventually the only delimiters. To add them to the list of default delimiters you would need to specify the default delimiters explicitly in the second argument, e.g.,&amp;nbsp;&lt;FONT face="courier new,courier"&gt;d=countw(string,' !$%&amp;amp;()*+,-./;&amp;lt;^|','d')&lt;/FONT&gt;&amp;nbsp;in an ASCII environment (resulting in different values for variable &lt;FONT face="courier new,courier"&gt;d&lt;/FONT&gt;&amp;nbsp;than with the empty second argument).&lt;/P&gt;</description>
      <pubDate>Mon, 23 Mar 2020 19:50:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Countw-n-and-d-Modifier/m-p/634257#M188244</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-03-23T19:50:09Z</dc:date>
    </item>
    <item>
      <title>Re: Countw n and d Modifier</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Countw-n-and-d-Modifier/m-p/634311#M188260</link>
      <description>Totally understood! Thanks so much, Quentin, I really appreciate it!</description>
      <pubDate>Tue, 24 Mar 2020 01:02:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Countw-n-and-d-Modifier/m-p/634311#M188260</guid>
      <dc:creator>Cecillia_Mao</dc:creator>
      <dc:date>2020-03-24T01:02:34Z</dc:date>
    </item>
    <item>
      <title>Re: Countw n and d Modifier</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Countw-n-and-d-Modifier/m-p/634312#M188261</link>
      <description>Dear Astounding, Thanks so much! I think FreelanceReinhard added some thoughts regarding delimiters below. In my case, the default blank was overridden and counted as a word.</description>
      <pubDate>Tue, 24 Mar 2020 01:10:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Countw-n-and-d-Modifier/m-p/634312#M188261</guid>
      <dc:creator>Cecillia_Mao</dc:creator>
      <dc:date>2020-03-24T01:10:21Z</dc:date>
    </item>
    <item>
      <title>Re: Countw n and d Modifier</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Countw-n-and-d-Modifier/m-p/634313#M188262</link>
      <description>Got it! Thanks a ton!</description>
      <pubDate>Tue, 24 Mar 2020 01:12:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Countw-n-and-d-Modifier/m-p/634313#M188262</guid>
      <dc:creator>Cecillia_Mao</dc:creator>
      <dc:date>2020-03-24T01:12:27Z</dc:date>
    </item>
  </channel>
</rss>

