Dear
I need help in my pgm to output only records that contain 'OTHER'. In the my data, there is one record with 'OTHER'. In the output dataset 'TWO' I am getting three records. Please suggest
data one;
input a $40.;
datalines;
contains OTHER
contains CHEMOTHERAPY
contains IMMUNOTHERAPY
contains IMMUNO
;
DATA TWO;
SET ONE;
IF index(UPCASE(A),'OTHER');
RUN;
output need
contains OTHER
Hello @knveraraju91 ,
chemOTHERapy and immunOTHERapy also contain the string 'OTHER' of course.
Maybe this code helps you out?
data one;
input a $40.;
datalines;
contains OTHER
contains CHEMOTHERAPY
contains IMMUNOTHERAPY
contains IMMUNO
;
run;
DATA TWO;
SET ONE;
where scan(upcase(a),2)='OTHER';
*IF index(UPCASE(A),'OTHER');
RUN;
Good luck,
Koen
INDEXW or FINDW to find words. Index and Find will find strings embedded in longer words.
DATA TWO; SET ONE; IF indexw(UPCASE(A),'OTHER'); RUN;
Indexw has an optional parameter for providing delimiters between words in case the blank is not sufficient. Suppose you have text like: this*that=something.
If you want to find "that" as a word you could provide * and = as additional delimiters:
if indexw(str,'that',' *=') then ...
Note the inclusion of the blank so that other places blank is still used as a delimiter.
Findw is similar but has a few more parameters and can use modifiers to indicate things like "all punctuation" and Ignore case for comparisons.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.