BookmarkSubscribeRSS Feed
thanikondharish
Fluorite | Level 6

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;

 

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

What do you mean by "is there any other coding?"?

 

Your code does what it is suppose to, it seems?

thanikondharish
Fluorite | Level 6
i mean any other short way
Astounding
PROC Star

You don't really need to create dob1:

 

dob = input(compress(name,,'kd'), ddmmyy8.);

mkeintz
PROC Star

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.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 2293 views
  • 0 likes
  • 5 in conversation