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

 

I have the following data and am trying to use the scan function to find a 10 character string starting with C-

 

PLP C-00201123 042718 OR State Change (1)
X C-00200838 042718 supplies surprise day 5 offer (1)
PLP C-00201124 042718 NJ State Change (1)
X C-00200834 042618 supplies surprise day 4 offer (1)
PTR C-00200836 042618 Encompass Subscribers Credit Card Expiring Soon (1)
PTR C-00200835 Inter-Intra Email 4-26-18 (1)
PTR C-00200837 042618 ELD Roadside Inspections Guide (1)
PTR C-00200953 Encompass Customer Webcast  4-25-18 Reminder (1)
TOD C-00120194 042518 TOD Newsletter - April 2018 (1)
PHR C-00200833 FMLA Invite 4-25-18 (1)
PCS C-00200831 042518 Fall Protection for Construction (1)
PTR C-00200832 042518 Roadcheck 2018 Whitepaper (1)
X C-00200830 042518 supplies surprise day 3 offer (1)
X C-00200827 042418 supplies surprise day 2 offer (1)
PWS C-00200829 KOL Invite (Cintas)  4-24-18 (1)
PWS C-00200828 KOL Invite 4-24-18 (1)
C-00200943 - Free 2290 Poster 04-16-2018 (3)
PTR C-00200524 042318 Encompass Appreciation Offer (1)
X C-00200826 042318 supplies surprise day 1 offer (1)
PTR C-00200954 ELDs and IFTA 4-23-18 (1)
C-00201191 Online Renewal - 1st Notice - sub expiring soon (2)

 

The following code gives me the data in two steps.  I was just wondering if there was another way to write this in one step?  If not,

I can work with this. Thanks!

 

NEW_CODE=scan(Sent_Mailing_Name,'1','C-'-2);
NEW_CODE2=scan(Sent_Mailing_Name,'2','C-'-2);

 

NEW_CODE  NEW_CODE2

PLP                C-00201123
X                     C-00200838
PLP                C-00201124
X                    C-00200834
PTR               C-00200836
PTR               C-00200835
PTR               C-00200837
PTR               C-00200953
TOD              C-00120194
PHR              C-00200833
PCS              C-00200831
PTR                C-00200832
X                      C-00200830
X                      C-00200827
PWS                C-00200829
PWS                C-00200828
C-00200943    -
PTR                 C-00200524
X                     C-00200826
PTR                C-00200954
C-00201191    Online
PTR                C-00201056
X                     C-00201050
C-00201191    Online

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

It looks like the first word that begins with "C-" is always your desired result.   If so, then this would work

 

  length new_code $10;
  new_code=substr(sent_mailing_name,index(sent_mailing_name,'C-'));
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

View solution in original post

3 REPLIES 3
mkeintz
PROC Star

It looks like the first word that begins with "C-" is always your desired result.   If so, then this would work

 

  length new_code $10;
  new_code=substr(sent_mailing_name,index(sent_mailing_name,'C-'));
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
cbrotz
Pyrite | Level 9

I need to look at FIND a little more.  When I first looked at it, it looks like it returns a location or something and then it would need to be used in other code based on location?  I am used to substr etc.  but does not hurt to learn something new.

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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