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

Hi, I am a beginner who is working on student edition of SAS. I exported the WhatsApp chat data of a group for 6 months. A part of it is as shown below ;

 

1/18/17, 6:57:00 PM: TSV: Everyone claps for Diana who got selected for job 💃🏻🤗🎉
1/18/17, 6:58:32 PM: Christopher Walken (techguy): 👏🏼
1/18/17, 6:58:55 PM: TSV: I'm so happy for you Diana More reasons to go shopping 💃🏻💃🏻💃🏻
1/18/17, 7:02:37 PM: Gaggan Anand (next desk): Awesome Diana
Congrats 👍🏽👏🏼

 

I am looking to categorize it into 3 or 4 variables. Date / Time separate or combined, Name and Message.

 

I tried to do it but not able to increase the length of data in name and message variable. The last sentence "congrats" also stays in date variable.

 

Can someone help me in the codes so that I can separate them and apply if for whole 6 months?

 

I tried as shown in the pic below.

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

When your code generates error is a good practice on this forum to post the log with the code and errors. Paste the result into a code box opened using the forum menu icon {I}.

SAS date / time reading informats do not like that , that was in the middle of the date and time. So you need to parse the data a bit.

 

One way:

DATA WHATSAPP;
   infile datalines dlm=":" ;
   INFORMAT dttxt $19. NAME $CHAR20. MESSAGE $CHAR100.;
   INPUT dttxt 1-19  NAME MESSAGE;
   date_time = input(compress(dttxt,','),anydtdtm.);
   format date_time datetime20.;
   drop dttxt;
DATALINES;
1/18/17, 6:57:00 PM: TSV: Everyone claps for Diana who got selected for job
1/18/17, 6:58:32 PM: Christopher Walken (techguy):
1/18/17, 6:58:55 PM: TSV: I'm so happy for you Diana More reasons to go shopping
1/18/17, 7:02:37 PM: Gaggan Anand (next desk): Awesome Diana Congrats
;
RUN;

I changed to code to use : as delimiter as the posted example did not actually correspond to the columns specified by @21 and @26 when copied to my editor.

 

View solution in original post

2 REPLIES 2
agsuthar
Calcite | Level 5
I tried code as shown below but did not get sufficient output.


DATA WHATSAPP;
INFORMAT DATE_TIME MDYAMPM18. NAME $CHAR20. MESSAGE $CHAR100.;
INPUT DATE_TIME @21 NAME @26 MESSAGE;
DATALINES;
1/18/17, 6:57:00 PM: TSV: Everyone claps for Diana who got selected for job
1/18/17, 6:58:32 PM: Christopher Walken (techguy):
1/18/17, 6:58:55 PM: TSV: I'm so happy for you Diana More reasons to go shopping
1/18/17, 7:02:37 PM: Gaggan Anand (next desk): Awesome Diana
Congrats
;
RUN;

PROC PRINT DATA = WHATSAPP;
FORMAT DATE_TIME MDYAMPM18.;
FORMAT NAME $CHAR20.;
FORMAT MESSAGE $CHAR100.;
RUN;
ballardw
Super User

When your code generates error is a good practice on this forum to post the log with the code and errors. Paste the result into a code box opened using the forum menu icon {I}.

SAS date / time reading informats do not like that , that was in the middle of the date and time. So you need to parse the data a bit.

 

One way:

DATA WHATSAPP;
   infile datalines dlm=":" ;
   INFORMAT dttxt $19. NAME $CHAR20. MESSAGE $CHAR100.;
   INPUT dttxt 1-19  NAME MESSAGE;
   date_time = input(compress(dttxt,','),anydtdtm.);
   format date_time datetime20.;
   drop dttxt;
DATALINES;
1/18/17, 6:57:00 PM: TSV: Everyone claps for Diana who got selected for job
1/18/17, 6:58:32 PM: Christopher Walken (techguy):
1/18/17, 6:58:55 PM: TSV: I'm so happy for you Diana More reasons to go shopping
1/18/17, 7:02:37 PM: Gaggan Anand (next desk): Awesome Diana Congrats
;
RUN;

I changed to code to use : as delimiter as the posted example did not actually correspond to the columns specified by @21 and @26 when copied to my editor.

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1774 views
  • 0 likes
  • 2 in conversation