DATA Step, Macro, Functions and more

Datatype macro

Accepted Solution Solved
Reply
Contributor
Posts: 71
Accepted Solution

Datatype macro

[ Edited ]

Hi, I need to validate if the value of a macro variable is numeric(float or Integer). Please suggest a way to do this.


Accepted Solutions
Solution
‎12-08-2016 06:42 AM
Super User
Posts: 10,046

Re: Check whether the value of a macro variable is numeric


%let x=12.34;
%let f=%datatyp(&x);

%put &x &f;

View solution in original post


All Replies
Super User
Posts: 19,877

Re: Check whether the value of a macro variable is numeric

Try and convert it to a numeric and check if it's not missing 

 

You can use INPUT. 

 

If input("&macrovariable", ?? Best12.) ne . Then put 'Numeric';

Super User
Super User
Posts: 7,997

Re: Check whether the value of a macro variable is numeric

[ Edited ]

Why use macro variables - which are only text - for numeric data in the first place?  Remember Macro Language is only a text generation system, it does nothing on its own, that is what Base SAS is for.  There is never a *need* to use macro.

 

That being said, if your developing a library tool with paramters, and you need to check it, then maybe something like:

...
data _null_;
  call symput('TEST',ifc(lengthn(compress("&THEVAR."," .","d")) > 0,"Y","N"));
run;

%if "&test."="Y" %then...
  %put Failed;
...

 Just to note, in the data _null_, you would do all your parameter checks, and then just output one result.

Super User
Posts: 19,877

Re: Check whether the value of a macro variable is numeric

@RW9Negative sign?

Contributor
Posts: 71

Re: Check whether the value of a macro variable is numeric

@RW9: Actually I am validating the parameters passed to a remote macro and need to print the error in log of my local machine
Solution
‎12-08-2016 06:42 AM
Super User
Posts: 10,046

Re: Check whether the value of a macro variable is numeric


%let x=12.34;
%let f=%datatyp(&x);

%put &x &f;

Super User
Posts: 19,877

Re: Check whether the value of a macro variable is numeric

Contributor
Posts: 71

Re: Check whether the value of a macro variable is numeric

Thanks a lot. You are a saviour Smiley Happy @Ksharp
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 255 views
  • 1 like
  • 4 in conversation