Help using Base SAS procedures

How to judge whether a maro variable is a pure numeric

Reply
Regular Contributor
Posts: 222

How to judge whether a maro variable is a pure numeric


Hello everyone,

I want to know whether a macro  variable is a pure numeric or it include some characters, how to do this?

For example:the macro  variable &notpure is NOT a pure numeric, it includes some characters('aqw').how to know this?

%let notpure=123aqw4567;

%let pure=12345;

Thanks

Mike

PROC Star
Posts: 7,474

Re: How to judge whether a maro variable is a pure numeric

Posted in reply to Mike_Davis

%let notpure=123aqw4567;

%put %sysfunc(notdigit(&notpure.));

%let pure=12345;

%put %sysfunc(notdigit(&pure.));

Regular Contributor
Posts: 222

Re: How to judge whether a maro variable is a pure numeric

Awesome,

Thanks Art!

Mike

Super User
Super User
Posts: 7,053

Re: How to judge whether a maro variable is a pure numeric

Posted in reply to Mike_Davis

Why not use the SAS supplied macro DATATYP ?

Regular Contributor
Posts: 222

Re: How to judge whether a maro variable is a pure numeric


Thank you Tom!

%macro test;
%let a=123;
%let b=a12;
%put 1:%DATATYP(&a);
%put 2:%DATATYP(&b);
%if %DATATYP(&b)=CHAR %then %put char;
%if %DATATYP(&b)=NUMERIC %then %put #;
%mend test;

%test;

Ask a Question
Discussion stats
  • 4 replies
  • 235 views
  • 6 likes
  • 3 in conversation