BookmarkSubscribeRSS Feed
krishnaavm123
Fluorite | Level 6

Hi Team,

 

I am currently working on a dataset where the Chattext column contains a long string of text that I need to split into multiple lines, as demonstrated in the desired output format below:

 

Attached file with input data and desired output results I'm looking for.

 

Thanks in Advance!

 

2 REPLIES 2
Tom
Super User Tom
Super User

Looks like you split the example some how, what logic did you use? Why did you split it at those locations?  Explain the rule.

 

Did you try any SAS code?  How well did it work?

 

PS  No need to attach a file.  You can post simple text using the Insert Code button to get a pop-up window.

Chat_id   Chattext
101       10/05/2024 10:15:00 krishna.vangalli@gmail.com hello Raju how are you 10/05/2024 10:16:15 Raju@gmail.com Hey krishna whatsup I'm doing good   
102       10/06/2024 11:15:00 krish.vangalli@gmail.com hello  10/06/2024 10:16:15 Raju@gmail.com Hey krishna whatsup I'm doing good
Ksharp
Super User
data have;
infile cards truncover;
input Chat_id   Chattext $200.;
cards;
101       10/05/2024 10:15:00 krishna.vangalli@gmail.com hello Raju how are you 10/05/2024 10:16:15 Raju@gmail.com Hey krishna whatsup I'm doing good   
102       10/06/2024 11:15:00 krish.vangalli@gmail.com hello  10/06/2024 10:16:15 Raju@gmail.com Hey krishna whatsup I'm doing good
;
data want;
 set have;
 pid=prxparse('/\d+\/\d+\/\d+/');
 s=1;e=length(Chattext);
 call prxnext(pid,s,e,Chattext,p,l);
 do while(p>0);
   _p=p;
   call prxnext(pid,s,e,Chattext,p,l);
   if p>0 then temp=substr(Chattext,_p,p-_p);
     else temp=substr(Chattext,_p);

   	 date=scan(temp,1,,'s');
	 time=scan(temp,2,,'s');
	 sender=scan(temp,3,,'s');
	 call scan(temp,3,p2,l2,,'s');
     chat_text=substr(temp,p2+l2);
     output;
 end;
 keep Chat_id   date          time        sender       chat_text  ;
 run;

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
  • 2 replies
  • 148 views
  • 0 likes
  • 3 in conversation