How to select only those records that have the word "AND" with single or multiple spaces before and after it.
Standarad
Standarad And Poor
Standarad and Poor
So would like to select the only :
Standarad And Poor
Standarad and Poor
if index(upcase(varname), ' AND ');
You would have to handle separately any cases where And is the first word, and so does not appear with a leading space.
You could use WHERE instead of IF (especially if you are subsetting as part of a SAS procedure).
data have;
input text:&$200.;
if prxmatch('m/\sand\s*/i',strip(text));
cards;
Standarad
Standarad And Poor
Standarad and Poor
;
the 'i' modifier in the findw function ignores the case.
data want;
set have;
if findw(varname,'and',' ','i');
run;
Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.
Explore Now →SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.