BookmarkSubscribeRSS Feed
thanikondharish
Calcite | Level 5

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
Calcite | Level 5
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

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

sas-innovate-2024.png

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.

 

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
  • 935 views
  • 0 likes
  • 5 in conversation