Hi, I need to validate if the value of a macro variable is numeric(float or Integer). Please suggest a way to do this.
%let x=12.34; %let f=%datatyp(&x); %put &x &f;
Try and convert it to a numeric and check if it's not missing
You can use INPUT.
If input("¯ovariable", ?? Best12.) ne . Then put 'Numeric';
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.
@RW9Negative sign?
%let x=12.34; %let f=%datatyp(&x); %put &x &f;
@Ksharp learned my new thing for the day 🙂
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.