BookmarkSubscribeRSS Feed
Smitha9
Fluorite | Level 6

Hi,

I have a datset which has 5digit numbers that ends with 2 or 4. I want to delete the entire row if the last digit is 4.

example:

ID         Sample

1        00012

2        00034

3        00032

4         00124

5         00432

 

I want to delete the row which has the last digit 4. In the above example, I want to delete 00034 and 00124.

Can I do this in SAS to remove if the 5th digit is 4.

 

thanks in advance.

 

 

3 REPLIES 3
SASKiwi
PROC Star

If Sample is character then this should do it:

data Want;
  set Have;
  if substr(Sample,5,1) = '4' then delete;
run;
sbxkoenk
SAS Super FREQ

Or like this :

data have;
input ID Sample $;
cards;
1        00012
2        00034
3        00032
4        00124
5        00432
;
run;

data want;
 set have;
 where reverse(strip(Sample)) NOT =: '4';
run;
/* end of program */

Koen

PaigeMiller
Diamond | Level 26

If the variable in numeric, you would use the MOD function

 

if mod(sample,10)=4 then delete;
--
Paige Miller

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 3 replies
  • 989 views
  • 2 likes
  • 4 in conversation