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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 570 views
  • 2 likes
  • 4 in conversation