BookmarkSubscribeRSS Feed
Prash
Calcite | Level 5

I am getting error for this code, not knowing where I am missing.

 

data want;

data have;

if centre in ('Shai','Hub','imen') and Date_of_Birth between mdy(3,01,1953) and mdy(6,30,1974) then status = 'pass';

run;

 

 

Not sure where I am missing, I tried with where as well but not succeeding, apart from that also checked with do end , But could not get the required result, Can any one help on this

Thanks

 

 

 

 

5 REPLIES 5
stat_sas
Ammonite | Level 13

Seems like you need set statement

 

data want;

set have;

if centre in ('Shai','Hub','imen') and Date_of_Birth between mdy(3,01,1953) and mdy(6,30,1974) then status = 'pass';

run;

Prash
Calcite | Level 5

Agree with you,

 

Actually it has to be

 

Data want;

set have;

run;

 

It was a typo sorry for that. However running the mentioned codes by replacing with Set is not deriving the expected result

Reeza
Super User
Also, you can't use BETWEEN with an IF statement, only a WHERE statement. So either change to where or switch the comparison to mdy(3, 1, 1953)<=date_of_birth<=mdy(6, 30, 1974)
Prash
Calcite | Level 5

Hello Reeza,

 

I got the solution, However if I use 'between and' for a date, and if I use 'Where' or 'IF' I am not getting the expected results, is it like if I am using 'between and' for a date can't I use 'where' and 'IF'

 

Thanks,

 

ballardw
Super User

Try:

 

if centre in ('Shai','Hub','imen') and (mdy(3,01,1953) le Date_of_Birth le mdy(6,30,1974)) then status = 'pass';

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
  • 5 replies
  • 868 views
  • 0 likes
  • 4 in conversation