BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rvksharma
Calcite | Level 5

Given a dataset wherein we have one variable EmployeeData contains contains the data as below.

 

EmployeeData

Ravi27Kumar

Avinash29Sharma

Jitender25Singh

Anu26Sirohi

 

I want data be splitted in 3 variables FirstName Age LastName. Please advise

 

Ravi 27 Kumar
Avinash 29 Sharma
Jitender 25 Singh
Anu 26 Sirohi

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star
One way:

First name = scan(employeedata, 1, '0123456789' ) ;
Last_name = scan(employeedata, 2, '0123456789' ) ;
Age = compress(employeedata,,'kd' ) ;

View solution in original post

4 REPLIES 4
Astounding
PROC Star
One way:

First name = scan(employeedata, 1, '0123456789' ) ;
Last_name = scan(employeedata, 2, '0123456789' ) ;
Age = compress(employeedata,,'kd' ) ;
ScottBass
Rhodochrosite | Level 12

In future post your code using the Insert SAS Code icon, using datalines. I have converted your "code" (text actually) only because it was trivial and didn't take much effort.

 

Here's another approach:

 

data have;
   input EmployeeData :$30.;
   datalines;
Ravi27Kumar
Avinash29Sharma
Jitender25Singh
Anu26Sirohi
;
run;

data want;
   rx=prxparse("/(.*?)(\d+)(.*)/o");
   set have;
   length FirstName $30 Age 8 LastName $30;
   if prxmatch(rx,strip(EmployeeData)) then do;
      FirstName   = prxposn(rx,1,EmployeeData);
      Age         = input(prxposn(rx,2,EmployeeData),best.);
      LastName    = prxposn(rx,3,EmployeeData);
   end;
run;

Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
ballardw
Super User

You might consider talking to whoever is providing data in that format, especially if this is actually business related and not some school exercise.

Any data interchanged should have a description so that the users can actually use the file. If data files do not have a delimiter then something else needs to be provided so that you KNOW where values start and end such as start and end columns. Guessing that a digit separates names is unreliable in some formats as people are obnoxious and will name there children, or pick a name, such as 3 just to be funny/ cute/ obnoxious.

 

A business process without an agreement as to how the file will be structured is likely to lead to numerous headaches.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 468 views
  • 1 like
  • 4 in conversation