DATA Step, Macro, Functions and more

Check and Verify for numeric data

Occasional Contributor
Posts: 9

Check and Verify for numeric data

I was wondering if there is a way to use the verify function with my check as a numeric interval. For example,


data want;

set have;

check= '1-10';

if verify(Age, check) ne 0 then put 'not allowed';



Thank you! 

Super User
Posts: 24,028

Re: Check and Verify for numeric data

[ Edited ]

No, because it's a character function, not numeric. 


There are relatively easy other ways, but I suspect you're also going to extend this beyond this specific example.


*check for integers 1 to 10;
if age in (1:10) then...;

*check for values 1 to 10, including endpoints;
if  1<=age<=10 then...;
Super User
Posts: 13,950

Re: Check and Verify for numeric data

For some uses a format might work to create output similar to what you want.


Proc format library=work;
value validage
1 - 10 ='Valid'
other  = 'Invalid';

data example;
   input Age;
   put Age= age validage.;

This approach is fairly flexible if you have similar variables that all use the same range for valid values. It will also work for character values with the proper format.



Depending on what is done with the information, such as a step later to recode to value, then perhaps an informat might be appropriate to read and recode at one step.

Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation