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

Hello! My data set has an ID number (character variable) and I want to filter some of observations.

 

The criteria is if the 3rd and the 4th digits are "RE", then delete.

 

For example, if the ID is ABRE5550, this observation should be deleted.

 

What code do I need to use? 

 

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
kiranv_
Rhodochrosite | Level 12
if substr(id, 3, 2) = "RE" then delete;

 

3 is starting position and 2 is length and you need quotes around the value 

View solution in original post

4 REPLIES 4
Reeza
Super User
Look at the SUBSTR() function.
dapenDaniel
Obsidian | Level 7
if substr(id, 3, 4) = RE then delete;

Is it correct? 

Reeza
Super User
Is RE a variable or text? If it's text it needs to be in quotes, if it's a variable then it's fine.
kiranv_
Rhodochrosite | Level 12
if substr(id, 3, 2) = "RE" then delete;

 

3 is starting position and 2 is length and you need quotes around the value 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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