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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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