BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

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

2 REPLIES 2
sbxkoenk
SAS Super FREQ

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

ballardw
Super User

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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 810 views
  • 2 likes
  • 3 in conversation