BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Aditi24
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
7 REPLIES 7
Reeza
Super User

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';

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Aditi24
Obsidian | Level 7
@RW9: Actually I am validating the parameters passed to a remote macro and need to print the error in log of my local machine
Ksharp
Super User

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

%put &x &f;

Aditi24
Obsidian | Level 7
Thanks a lot. You are a saviour 🙂 @Ksharp

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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