Contributor
Posts: 25

# Using an if statement with an AND

Total_DOB = input(catx("/", month_dob, day_dob, year_dob),?? mmddyy8.);
if ((month_dob = 29) AND (day_dob= 02)) then Total_DOB = mdy(03,01,year_dob)-1;
else Total_DOB = mdy(month_dob,15,year_dob);

or

Total_DOB = input(catx("/", month_dob, day_dob, year_dob),?? mmddyy8.);
if ((Total_DOB = .) AND (month_dob = 29)) then Total_DOB = mdy(03,01,year_dob)-1;
else Total_DOB = mdy(month_dob,15,year_dob);

neither work and just change all of the dates with a . to the day with 15
Posts: 1,163

## Re: Using an if statement with an AND

I would try the below approach if there are only two conditions

1) if the month_dob=02 and day_dob=29 then you want it to be imputed to 01MarYYYY. imputing only the day and month. if it is the case then what you mentioned is incorrect, you codes month_dob=29 which should be 02 as i mentioned so you reversed it.

2) if the above condition is not met then  you would like to impute only the day to 15.

Please let me know if these are only two conditions you are checking.

Thanks,
Jag
Super User
Posts: 6,934

## Re: Using an if statement with an AND

Is YEAR_DOB really a two-digit year?  That would be the only reason to use ?? MMDDYY8.  But if YEAR_DOB is really a four-digit year, MMDDYY8 isn't long enough.  You need to switch to MMDDYY10. because you have to count the slashes as part of the characters you are reading.

It looks like you have switched around the month and the day.  It is highly unlikely that you will ever find MONTH_DOB=29.

Posts: 5,625

## Re: Using an if statement with an AND

Did you know that function MDY can handle two digits year values? If the problem is that you are sometimes missing the day value, then all you need is:

Total_DOB = mdy (month_dob, coalesce(day_dob, 15), year_dob);

format total_DOB yymmdd10.;

PG
Super User
Posts: 10,574

## Re: Using an if statement with an AND

First of all, are month_dob, day_dob, year_dob numeric or character? In your code snippet you treat them as both, which is at least not sound programming practice.

Assuming that they are numeric, I'd do

``````Total_DOB = input(put(year_dob,z4.) !! put(month_dob,z2.) !! put(day_dob,z2.),yymmdd8.);
if Total_DOB = .
then do;
if ((month_dob = 29) and (day_dob = 2))
then Total_DOB = mdy(3,1,year_dob)-1;
else if day_dob = .
then Total_DOB = mdy(month_dob,15,year_dob);
end;``````
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Discussion stats
• 4 replies
• 182 views
• 1 like
• 5 in conversation