<?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: Checking if macro variable is numeric or not. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-macro-variable-is-numeric-or-not/m-p/512445#M138026</link>
    <description>&lt;P&gt;very nice&lt;/P&gt;</description>
    <pubDate>Tue, 13 Nov 2018 04:12:12 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-11-13T04:12:12Z</dc:date>
    <item>
      <title>Checking if macro variable is numeric or not.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-macro-variable-is-numeric-or-not/m-p/512425#M138010</link>
      <description>&lt;P&gt;I'm trying to write where any given macro variable can be numeric or character as the list of possible input value could be any integer, possibly preceded or followed by a character (i.ee = -1, 0, 1, d1, w9e), but something is off. See below for the simplified code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Checking if variable is integer:

%macro isnum (mv);
   %eval(not %sysfunc(verify(&amp;amp;mv,-0123456789)));
%mend isnum;

%macro DefineDate(dt1,dt2,dt3);														
	...				
	%do i = 1 %to 3;
		%put Test dt&amp;amp;i. = &amp;amp;&amp;amp;dt&amp;amp;i.;
		%if %length(&amp;amp;&amp;amp;dt&amp;amp;i.) ne 0 %then %do;
			%put Variable dt&amp;amp;i. = &amp;amp;&amp;amp;dt&amp;amp;i.;
			%if %isnum(&amp;amp;&amp;amp;dt&amp;amp;i.) = 1 %then %do;
				%put dt&amp;amp;i. isnum successful;
			%end;
			%else %do;
				%put dt&amp;amp;i. isnum did not run;
			%put dt&amp;amp;i. numericity is %isnum(&amp;amp;&amp;amp;dt&amp;amp;i.);
		%end;
		%else %put dt&amp;amp;i. does not exist;
	%end;	
%mend;
%DefineDate(dm1,0)&lt;/PRE&gt;
&lt;P&gt;The output to the log is:&lt;/P&gt;
&lt;P&gt;Test dt1 = dm1&lt;BR /&gt;Variable dt1 = dm1&lt;BR /&gt;dt1 isnum did not run&lt;BR /&gt;dt1 numericity is 0;&lt;BR /&gt;Test dt2 = 0&lt;BR /&gt;Variable dt2 = 0&lt;BR /&gt;dt2 isnum did not run&lt;BR /&gt;dt2 numericity is 1;&lt;BR /&gt;Test dt3 =&lt;BR /&gt;dt3 does not exist&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can't understand why I can't get the %IF conditional to run in the second step, despite it returning 1 in the identical put statement.&lt;BR /&gt;&lt;BR /&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 13 Nov 2018 02:26:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-macro-variable-is-numeric-or-not/m-p/512425#M138010</guid>
      <dc:creator>WimB</dc:creator>
      <dc:date>2018-11-13T02:26:03Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if macro variable is numeric or not.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-macro-variable-is-numeric-or-not/m-p/512426#M138011</link>
      <description>I think the NOT in the %eval is incorrect. Would the notdigit or INPUTN maybe be easier to use than verify? If you explain your latter usage of these values, there may be other options.</description>
      <pubDate>Tue, 13 Nov 2018 02:32:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-macro-variable-is-numeric-or-not/m-p/512426#M138011</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-11-13T02:32:16Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if macro variable is numeric or not.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-macro-variable-is-numeric-or-not/m-p/512428#M138012</link>
      <description>&lt;P&gt;In my opinion&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;is bang on target with notdigit being the sweetest. However, You could use %sysevalf to evaluate to a Boolean result. I learned that from Guru of Gurus&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;&amp;nbsp;. Little too late and tired in Chicago night, but I hope I comprehended the topic.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Nov 2018 02:44:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-macro-variable-is-numeric-or-not/m-p/512428#M138012</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-13T02:44:16Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if macro variable is numeric or not.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-macro-variable-is-numeric-or-not/m-p/512429#M138013</link>
      <description>I tried notdigit, but it only works on character variables and then I'd get the error for numeric inputs that there is a NUM variable where notdigit expects a CHAR variable.&lt;BR /&gt;&lt;BR /&gt;Also not sure about the "not" in the %eval being incorrect: if it was, why would it return a 1 in the put statement for the correct variable?&lt;BR /&gt;&lt;BR /&gt;I'll struggle on for a bit trying to see another solution with notdigit and ssyevalf. Report back later.</description>
      <pubDate>Tue, 13 Nov 2018 02:49:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-macro-variable-is-numeric-or-not/m-p/512429#M138013</guid>
      <dc:creator>WimB</dc:creator>
      <dc:date>2018-11-13T02:49:59Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if macro variable is numeric or not.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-macro-variable-is-numeric-or-not/m-p/512430#M138014</link>
      <description>All macro variables are character to start so anydigit will work, make sure to not use quotes.</description>
      <pubDate>Tue, 13 Nov 2018 02:55:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-macro-variable-is-numeric-or-not/m-p/512430#M138014</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-11-13T02:55:51Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if macro variable is numeric or not.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-macro-variable-is-numeric-or-not/m-p/512431#M138015</link>
      <description>&lt;P&gt;Ok, I'll retry and update in a bit. Thanks for your time, much appreciated!&lt;/P&gt;</description>
      <pubDate>Tue, 13 Nov 2018 02:57:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-macro-variable-is-numeric-or-not/m-p/512431#M138015</guid>
      <dc:creator>WimB</dc:creator>
      <dc:date>2018-11-13T02:57:17Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if macro variable is numeric or not.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-macro-variable-is-numeric-or-not/m-p/512432#M138016</link>
      <description>&lt;P&gt;a simple test-log report&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2078 %put %sysfunc(notdigit(a123));&lt;BR /&gt;1&lt;BR /&gt;&lt;BR /&gt;2081 %put %sysfunc(notdigit(123));&lt;BR /&gt;0&lt;/P&gt;</description>
      <pubDate>Tue, 13 Nov 2018 03:01:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-macro-variable-is-numeric-or-not/m-p/512432#M138016</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-13T03:01:48Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if macro variable is numeric or not.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-macro-variable-is-numeric-or-not/m-p/512433#M138017</link>
      <description>Do you need to account for decimals and percentages or will it always be integers?</description>
      <pubDate>Tue, 13 Nov 2018 03:04:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-macro-variable-is-numeric-or-not/m-p/512433#M138017</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-11-13T03:04:03Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if macro variable is numeric or not.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-macro-variable-is-numeric-or-not/m-p/512434#M138018</link>
      <description>&lt;P&gt;brilliant question and&lt;STRIKE&gt; %sysevalf has the answer&lt;/STRIKE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;log:&lt;BR /&gt;&amp;nbsp;%put %SYSEVALF( %sysfunc(notdigit(&lt;STRONG&gt;123.22&lt;/STRONG&gt;)) , boolean );&lt;BR /&gt;1&lt;BR /&gt;I think my usage is wrong but we are close&lt;/P&gt;</description>
      <pubDate>Tue, 13 Nov 2018 03:14:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-macro-variable-is-numeric-or-not/m-p/512434#M138018</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-13T03:14:05Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if macro variable is numeric or not.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-macro-variable-is-numeric-or-not/m-p/512436#M138019</link>
      <description>&lt;P&gt;The %isnum macro also returned 1, despite the %IF not returning true for checking = 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%put dt&amp;amp;i. numericity is %isnum(&amp;amp;&amp;amp;dt&amp;amp;i.)&lt;/PRE&gt;
&lt;P&gt;This returns dt2 numericity is 1, so I got that far too.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I also tried NOTDIGIT and I got this in the log:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ERROR: Required operator not found in expression: notdigit(&amp;amp;&amp;amp;dt&amp;amp;i.) = 0 
ERROR: The macro DEFINEDATE will stop executing.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think I'll give up on these methods for now and try to use prxmatch for a bit. This is breaking my mind why it returns 1 in a %PUT, but can't evaluate %IF %ISNUM(&amp;amp;&amp;amp;dt&amp;amp;i.) = 1 as true at the same time with all other proposed solutions giving me errors.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Nov 2018 03:17:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-macro-variable-is-numeric-or-not/m-p/512436#M138019</guid>
      <dc:creator>WimB</dc:creator>
      <dc:date>2018-11-13T03:17:42Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if macro variable is numeric or not.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-macro-variable-is-numeric-or-not/m-p/512438#M138021</link>
      <description>&lt;P&gt;I will test tomorrow morning and get to the bottom of it but I'm more than 100% certain , somebody else will give you the much needed solution while my night passes by sleeping. Hang in there&lt;/P&gt;</description>
      <pubDate>Tue, 13 Nov 2018 03:45:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-macro-variable-is-numeric-or-not/m-p/512438#M138021</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-13T03:45:18Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if macro variable is numeric or not.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-macro-variable-is-numeric-or-not/m-p/512444#M138025</link>
      <description>&lt;P&gt;I just been able to solve it!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%if %sysfunc(prxmatch('^-?\d+$',&amp;amp;&amp;amp;dt&amp;amp;i.)) = 1 %then %do;&lt;/PRE&gt;
&lt;P&gt;This did the trick for me and should be easily changable should the requirements someday change to include decimals &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Nov 2018 04:06:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-macro-variable-is-numeric-or-not/m-p/512444#M138025</guid>
      <dc:creator>WimB</dc:creator>
      <dc:date>2018-11-13T04:06:39Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if macro variable is numeric or not.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-macro-variable-is-numeric-or-not/m-p/512445#M138026</link>
      <description>&lt;P&gt;very nice&lt;/P&gt;</description>
      <pubDate>Tue, 13 Nov 2018 04:12:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-macro-variable-is-numeric-or-not/m-p/512445#M138026</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-13T04:12:12Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if macro variable is numeric or not.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-macro-variable-is-numeric-or-not/m-p/512455#M138034</link>
      <description>&lt;P&gt;The real&amp;nbsp; problem is that you included a semi-colon in your macro "function".&amp;nbsp; A macro that only generates part of a statement cannot generate a semi-colon because that will prematurely terminate any statement that you try to use it in.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;1    %macro isnum (mv);
2       %eval(not %sysfunc(verify(%superq(mv),-0123456789)))
3    %mend isnum;
4
5    %put %isnum(fred);
0
6    %put %isnum(123);
1
7    %put %isnum(-1.2.3);
0
8    %put %isnum();
1&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Nov 2018 05:39:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-macro-variable-is-numeric-or-not/m-p/512455#M138034</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-11-13T05:39:54Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if macro variable is numeric or not.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-macro-variable-is-numeric-or-not/m-p/512494#M138052</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/38138"&gt;@WimB&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This did the trick for me and should be easily changable should the requirements someday change to include decimals &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;For more general types of numeric values (including decimals and scientific notation) there's also the &lt;A href="https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=p14qy9r4wu1an0n11kfn30idvy20.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;%DATATYP Autocall Macro&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Nov 2018 09:58:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-macro-variable-is-numeric-or-not/m-p/512494#M138052</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-11-13T09:58:06Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if macro variable is numeric or not.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-macro-variable-is-numeric-or-not/m-p/512528#M138067</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %datatyp(fred);
%put %datatyp(123);
%put %datatyp(-1.2.3);
%put %datatyp();&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Nov 2018 13:21:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-macro-variable-is-numeric-or-not/m-p/512528#M138067</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-11-13T13:21:41Z</dc:date>
    </item>
  </channel>
</rss>

