In my source file, i have 2 columns For Eg:
Name DOJ
Ram 13/12/1988
Kumar 21/05/1989
Ishant 110488
Can we use IFN Function here?
IFN(DOJ = 'DATE FORMAT',DOJ,default date)
whether it will work?
I tried but no fruitful result.
Help me on this.
Hi,
What value have you tried for 'DATE FORMAT'? The equality test will just try to match the values on either side of the equal sign.
What error or warning message are you getting for the value you have tried?
Are you just trying to make sure the value of DOJ conforms to a certain format or is equal to a certain value?
Regards,
Amir.
Hi,
I dont know what to give in that 'DATE FORMAT'.
I need to check the format(need to be in dd/mm/yyyy).
For Eg: If DOJ is 13/12/1988 means o/p will be same
If DOJ is 13121988 means o/p will be any default date.
Its possible by using IFN function?
If not,how to proceed further.
Hi Helannivas,
Name DOJ
Ram 13/12/1988
Kumar 21/05/1989
Ishant 110488
In your input dataset Name and Doj both the variables are character please correct me if my understanding is wrong.
Hi Helannivas,
The following code will solve your problem if the data type of DOJ is Character in your input dataset.
data out_d;
set in_d;
pos=findc(doj,'/',1);
if pos = 0 then new_d = mdy(month(substr(doj,3,2)),day(substr(doj,1,2)),year(substr(doj,5,2)));
else new_d = mdy(month(substr(doj,4,2)),day(substr(doj,1,2)),year(substr(doj,7,4)));
format new_d ddmmyy8.;
run;
Please give your feedback.
Thank you.
Gaurang Patel
Hi,
In your code you show:
IFN(DOJ = 'DATE FORMAT',DOJ,default date)
The ifn function returns a numeric expression, so you can only return DOJ if it is numeric; ifc might be an alternative.
You have shown that some values of DOJ have '/' and some do not which would imply it is character.
Is DOJ supposed to be a numeric or a character variable?
SAS holds date values as numerics and a lot of SAS functions expect dates as numerics.
Regards,
Amir.
Hi,
If DOJ is a character variable then you could try something like:
data want;
set have;
retain default '01/01/2000';
doj2=ifc(prxmatch('/\d\d\/\d\d\/\d{4}/',doj),doj,default);
run;
Regards,
Amir.
Message was edited by: Amir Malik - used retain instead of assignment.
The fact that your data is in different formats indicates that the variable is character. In which case you can use a PERL regular expression to check the format you're looking for (you could expand on my example below to ensure the numbers entered are valid for dates). If you just wanted to convert these values to dates then you can use the ANYDTDTE. informat which will convert all the examples you provided.
data have;
input name $ doj $ :10.;
datewant1=input(doj,anydtdte10.);
datewant2=ifn(prxmatch('/\d{2}\/\d{2}\/\d{4}/',doj)=0,today(),input(doj,anydtdte10.));
format datewant: date9.;
datalines;
Ram 13/12/1988
Kumar 21/05/1989
Ishant 110488
;
run;
Hi. If the dates are always day-month-year, you can use a DDMMYY. informat since it works both with and without intervening slashes .
data x;
input name : $10. xyz : $10.;
datalines;
Ram 13/12/1988
Kumar 21/05/1989
Ishant 110488
Armondo 31122012
Steve 28/02/10
;
data x;
format doj ddmmyy10.;
set x;
doj = input(xyz,ddmmyy10.);
run;
doj name xyz
13/12/1988 Ram 13/12/1988
21/05/1989 Kumar 21/05/1989
11/04/1988 Ishant 110488
31/12/2012 Armondo 31122012
28/02/2010 Steve 28/02/10
Hi Mike,
Welcome back!!! Hope to see you soon!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.