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

I have a column of interaction logs that vary in length and I am looking to extract just the "Subject: CDF" portion (see the example below) of the string of characters.  I would normally use the subpad or scan or substr functions, in this case the position of the "S" in the "Subject: CDF" portion changes from row to row.

Any Ideas?

Data example:

"11:58:35: Created interaction.
11:58:35: QUEUENAME
11:58:35: Logging To
11:58:35: To: Mailbox, XXXXXX [XXXXXX@abc.com]
11:58:35: Logging From
11:58:35: From: xxxxxxxx@abc.com
11:58:35: Logging Subject
11:58:35: Subject: CDF IA 2017-08-17T11:50:38
11:58:35: Check State NonPilot
11:58:35: Auto Attendant
11:58:35: Get Work Type....."

What I want to return is just "CDF" of the subject line.  Also the length of the "CDF" can vary from line to line.  That is in the first row it might be "CDF", however the next row might be "FGHIJ", etc.

 

Thanks! 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@gregor1 wrote:

Thanks BallarW for your quick reply.  This data is from a data set already in SAS and not an external import.  My desired return would not have spaces, but would have a dash (e.g., "CDE-2").


May be the code will help with reading the next iteration of the data.

 

Scan should not be affected by the position of the "S" in subject. You should show more examples and the SCAN code you attempted that did not work as expected. Unless by Position you actually mean the word count before Subject is encountered, i.e. not immediately after the timestamp.

View solution in original post

4 REPLIES 4
ballardw
Super User

Is this reading an external file or are you asking about parsing an existing character variable?.

 

If you are reading from an external file one of the options available is the read "at" @.

 

data example;
   input @"Subject: " code $;
datalines;
11:58:35: Subject: CDF IA 2017-08-17T11:50:38
11:58:35: garbage garbage Subject: PDQfgs 
;

Any appropriate informat could be used for the variable. The default length with $ is 8 characters.

The tricky part is if you have spaces such as wanting "CDF IA" as the result.

gregor1
Quartz | Level 8

Thanks BallarW for your quick reply.  This data is from a data set already in SAS and not an external import.  My desired return would not have spaces, but would have a dash (e.g., "CDE-2").

gregor1
Quartz | Level 8

Additional info: I did use the index function and made it binary, but I am wanting the actual partial string return instead of a 0 or 1.

ballardw
Super User

@gregor1 wrote:

Thanks BallarW for your quick reply.  This data is from a data set already in SAS and not an external import.  My desired return would not have spaces, but would have a dash (e.g., "CDE-2").


May be the code will help with reading the next iteration of the data.

 

Scan should not be affected by the position of the "S" in subject. You should show more examples and the SCAN code you attempted that did not work as expected. Unless by Position you actually mean the word count before Subject is encountered, i.e. not immediately after the timestamp.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 4 replies
  • 572 views
  • 1 like
  • 2 in conversation