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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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