BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Smitha9
Fluorite | Level 6

I have a data.

ID   number

1    10022

2    12332

3    12334

4    13452

5    13454

I want to delete the ID which has "number" with last digit which has "4"

I want,

1  10022

2 12332

3 13452

thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

@Smitha9 wrote:
It is a character, the "number" if its ends with "4" I want to delete the whole row. thanks
if char(number,length(number))='4' then delete;

View solution in original post

5 REPLIES 5
Reeza
Super User
Is it a numeric or character variable?
Assuming character...but if it's numeric use SUBSTRN instead of SUBSTR.

where substr(number, length(number)-1) ne '4'
Smitha9
Fluorite | Level 6
It is a character, the "number" if its ends with "4" I want to delete the whole row. thanks
Tom
Super User Tom
Super User

@Smitha9 wrote:
It is a character, the "number" if its ends with "4" I want to delete the whole row. thanks
if char(number,length(number))='4' then delete;
Shmuel
Garnet | Level 18

data want;

set have;

     if substr(put(number,z5.),5,1) = '4' then delete;

run;

ed_sas_member
Meteorite | Level 14

Hi @Smitha9 

Here is another approach using pearl regular expressions:

data want;
	set have;
	if prxmatch('/4\s*$/',number) then delete;
run;

The PRXMATCH() function looks for the pattern 4 followed by 0, 1 or more blanks (\s*) at the end of the string ($) in the variable 'number'.

Best,

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

Register now!

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
  • 5 replies
  • 2168 views
  • 1 like
  • 5 in conversation