<?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 numeric values in macro parameter in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Count-numeric-values-in-macro-parameter/m-p/266867#M52693</link>
    <description>&lt;P&gt;Probably misunderstanding how COUNT works. Count counts the number of times a substring appears in a string.&lt;/P&gt;
&lt;P&gt;Count("xyxzxb 123","x") would return 3 times that X appears in the string.&lt;/P&gt;
&lt;P&gt;%let x= 1,2,3;&lt;/P&gt;
&lt;P&gt;%let count=%sysfunc(n(x)); would give you count but the list would have to be comma separated which in general is a suboptimal choice with macro variables and fails miserably if any nonnumeric noncomma characters are encountered.&lt;/P&gt;</description>
    <pubDate>Wed, 27 Apr 2016 21:14:05 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2016-04-27T21:14:05Z</dc:date>
    <item>
      <title>Count numeric values in macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-numeric-values-in-macro-parameter/m-p/266814#M52661</link>
      <description>&lt;P&gt;I am trying to calculate the number of numeric values in a macro parameter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code below works for character strings-&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let x = A B C;&lt;/P&gt;
&lt;P&gt;%let n = %SYSFUNC(COUNTW(&amp;amp;x));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code below does not work for numeric values-&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let x = 10 20 50;&lt;/P&gt;
&lt;P&gt;%let n = %SYSFUNC(COUNT(&amp;amp;x));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know COUNT does not work like this. Which function i can use to solve it?&lt;/P&gt;</description>
      <pubDate>Wed, 27 Apr 2016 18:54:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-numeric-values-in-macro-parameter/m-p/266814#M52661</guid>
      <dc:creator>Ujjawal</dc:creator>
      <dc:date>2016-04-27T18:54:49Z</dc:date>
    </item>
    <item>
      <title>Re: Count numeric values in macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-numeric-values-in-macro-parameter/m-p/266817#M52663</link>
      <description>&lt;P&gt;For your example, you can still use COUNTW.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you have more complex situations, such as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let x = 20 abc 50 A1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, what would you like the result to be?&lt;/P&gt;</description>
      <pubDate>Wed, 27 Apr 2016 19:01:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-numeric-values-in-macro-parameter/m-p/266817#M52663</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-04-27T19:01:00Z</dc:date>
    </item>
    <item>
      <title>Re: Count numeric values in macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-numeric-values-in-macro-parameter/m-p/266834#M52673</link>
      <description>&lt;P&gt;%let x = 20 abc 50 A1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;It should return 2 since two values are numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Apr 2016 19:35:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-numeric-values-in-macro-parameter/m-p/266834#M52673</guid>
      <dc:creator>Ujjawal</dc:creator>
      <dc:date>2016-04-27T19:35:51Z</dc:date>
    </item>
    <item>
      <title>Re: Count numeric values in macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-numeric-values-in-macro-parameter/m-p/266836#M52675</link>
      <description>&lt;P&gt;Counting numeric vs. character separately is much harder.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But COUNTW will work with a list of numeric values. &amp;nbsp;There must be some other problem. &amp;nbsp;You can always post the code that gives you a blank.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Apr 2016 19:36:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-numeric-values-in-macro-parameter/m-p/266836#M52675</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-04-27T19:36:20Z</dc:date>
    </item>
    <item>
      <title>Re: Count numeric values in macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-numeric-values-in-macro-parameter/m-p/266867#M52693</link>
      <description>&lt;P&gt;Probably misunderstanding how COUNT works. Count counts the number of times a substring appears in a string.&lt;/P&gt;
&lt;P&gt;Count("xyxzxb 123","x") would return 3 times that X appears in the string.&lt;/P&gt;
&lt;P&gt;%let x= 1,2,3;&lt;/P&gt;
&lt;P&gt;%let count=%sysfunc(n(x)); would give you count but the list would have to be comma separated which in general is a suboptimal choice with macro variables and fails miserably if any nonnumeric noncomma characters are encountered.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Apr 2016 21:14:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-numeric-values-in-macro-parameter/m-p/266867#M52693</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-04-27T21:14:05Z</dc:date>
    </item>
    <item>
      <title>Re: Count numeric values in macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-numeric-values-in-macro-parameter/m-p/266890#M52700</link>
      <description>&lt;P&gt;How about this :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro count_digit(t=);
%local temp count;
%let count=0;
 %do i=1 %to %sysfunc(countw(&amp;amp;t));
  %let temp=%scan(&amp;amp;t,&amp;amp;i);
  %if %datatyp(&amp;amp;temp)=NUMERIC %then %do; 
   %let count=%eval(&amp;amp;count+1); 
  %end;
 %end;
&amp;amp;count 
%mend;



%let x = 20 abc 50 A1;
%let n = %count_digit(t=&amp;amp;x);

%put &amp;amp;n;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Apr 2016 01:49:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-numeric-values-in-macro-parameter/m-p/266890#M52700</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-04-28T01:49:33Z</dc:date>
    </item>
    <item>
      <title>Re: Count numeric values in macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-numeric-values-in-macro-parameter/m-p/266948#M52712</link>
      <description>&lt;P&gt;Great suggestion from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp﻿&lt;/a&gt;&amp;nbsp;(as always). The %DATATYP autocall macro would even recognize leading plus or minus signs, decimal points or scientific notation (...E-6) as valid parts of numeric values. If this more general type of numeric "words" could occur, however, the sets of delimiters used by both COUNTW and %SCAN should be restricted (e.g. reduced to blanks, as shown below), as otherwise plus and minus signs and decimal points would be regarded as delimiters:&lt;/P&gt;
&lt;PRE&gt;countw(&amp;amp;t,%str( ))&lt;/PRE&gt;
&lt;PRE&gt;%scan(&amp;amp;t,&amp;amp;i,%str( ))&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Apr 2016 13:48:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-numeric-values-in-macro-parameter/m-p/266948#M52712</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-04-28T13:48:48Z</dc:date>
    </item>
  </channel>
</rss>

