- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
--------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
--------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
SCAN does not find strings with specific content.
Use the FIND function instead.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.