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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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