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: Call for Content

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 444 views
  • 1 like
  • 3 in conversation