data s;
name='ram28062018kumar' ;
output ;
name='venkat15072018sharma' ;
output;
run;
/*this my code to extract first name ,last name,dob.
is there any other coding?*/
data s1 ;
set s ;
finame=substr(name,1,anydigit(name)-1) ;
laname=reverse(substr(reverse(name),1,anydigit(reverse(name))-1));
dob1=compress(name,' ','kd') ;
dob= input(compress(substr(dob1,1,2)||'-'||substr(dob1,3,2)||'-'||substr(dob1,5,4)),ddmmyy10.);
format dob ddmmyyd10. ;
drop dob1;
run;
What do you mean by "is there any other coding?"?
Your code does what it is suppose to, it seems?
You don't need to insert hyphens in the date string; just use the ddmmyy8. informat.
Otherwise, your code looks fine.
You don't really need to create dob1:
dob = input(compress(name,,'kd'), ddmmyy8.);
You've already have good advice on getting dob. Here's a simplication for first and last names:
fname=scan(name,1,'0123456789');
lname=scan(name,-1,'0123456789');
The "-1" argument for scan in the lname assignment says to count backwards from the right-most word. This mean you don't have to worry about how many digits are in the dob value.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.