- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I have this data set and need to select the observations that have a particular character in the string and then (edit) spit out RETURN the particular string containing that character..
For example, if I want the observations containing 'G' then I'd need to get these: ZGZZX, GZZZZ, HSGZZ. If I wanted the observations containing 'X' then I'd return: ZGZZX
Thank you
data temp; input string $; datalines; ZGZZX GZZZZ ZZZZZ HSGZZ ; run;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Data want;
Set have;
If find(‘G’, variable)>0;
Run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
"spit out" is certainly ambiguous.
The INDEX function is one way to find single characters anywhere in a string.
rc = index(string, 'G');
the variable RC will have a value greater than 0 if G is found. Note that is a case sensitive comparison and would not find "g".
Other search functions such as FINDC may also work depending on exact requirements.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you, I edited my post to be more clear. I know to use INDEX (I believe the value returned would be the position where the character is found within the string) but I would like for the program to return the actual string where the character was found.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Data want;
Set have;
If find(‘G’, variable)>0;
Run;