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.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.