- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
One of my variables is made up of long strings. Similar to the following:
CODE
01|02|03|04|07|0A|0B|0C
01|02|03|04|05|0A|0B
I have tried using % wildcard operator, which works in SQL, but I couldn't get it to work in SAS. I also tried using * which I had seen used in another similar question. I would like to use an IF THEN statement to do the following:
IF CODE CONTAINS '03' THEN DO;
Unfortunately only arithmetic operators can be used with IF THEN statements. I considered using the SUBSTR function, but I don't know the starting position of the codes, they can change for each observation. Any advice or ideas on how I can solve this issue?
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
if find(code,'03') then do;
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Anthony_eng wrote:
One of my variables is made up of long strings. Similar to the following:
CODE
01|02|03|04|07|0A|0B|0C
01|02|03|04|05|0A|0B
I have tried using % wildcard operator, which works in SQL, but I couldn't get it to work in SAS. I also tried using * which I had seen used in another similar question. I would like to use an IF THEN statement to do the following:
IF CODE CONTAINS '03' THEN DO;
Unfortunately only arithmetic operators can be used with IF THEN statements. I considered using the SUBSTR function, but I don't know the starting position of the codes, they can change for each observation. Any advice or ideas on how I can solve this issue?
INDEXW/FINDW are functions you'll want.
FIND will find 01 within 001.
I think the statement in purple contradicts itself, not sure why you think "only arithmetic operators can be used with IF THEN statements".