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 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of 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
  • 616 views
  • 2 likes
  • 4 in conversation