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
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;
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: