BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8

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

3 REPLIES 3
Astounding
PROC Star

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).

Jagadishkatam
Amethyst | Level 16
data have;
input text:&$200.;
if prxmatch('m/\sand\s*/i',strip(text));
cards;
Standarad
Standarad And Poor
Standarad and   Poor
;
Thanks,
Jag
r_behata
Barite | Level 11

the 'i' modifier in the findw function ignores the case.

 

data want;
	set have;
	if findw(varname,'and',' ','i');
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 3 replies
  • 752 views
  • 1 like
  • 4 in conversation