03-19-2018 12:04 PM - edited 03-19-2018 12:15 PM
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
data temp; input string $; datalines; ZGZZX GZZZZ ZZZZZ HSGZZ ; run;
03-19-2018 12:13 PM
"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.
03-19-2018 12:22 PM
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.
Need further help from the community? Please ask a new question.