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;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 635 views
  • 1 like
  • 3 in conversation