BookmarkSubscribeRSS Feed
emkotnik
Calcite | Level 5

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

run;

 

Thank you! 

2 REPLIES 2
Reeza
Super User

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...;
ballardw
Super User

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

data example;
   input Age;
   put Age= age validage.;
datalines;
1
3
.
15
;
run;

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 662 views
  • 0 likes
  • 3 in conversation