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

Hello, 

I have a numeric variable that is 6 numbers in length. I'd like to use SQL to only keep the numbers that are 3 digits long. So, for example, I would keep 123 but not 1234 or 12345 or 123456. 

 

Thanks. 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

In SQL, have it filter for any value between 100 and 999.

--
Paige Miller

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

In SQL, have it filter for any value between 100 and 999.

--
Paige Miller
NickK
Fluorite | Level 6

So now the question is if the variable is character, how do I filter on that?

ballardw
Super User

@NickK wrote:

So now the question is if the variable is character, how do I filter on that?


where length(variablename) =3

 

unless you have leading spaces in your character variable, then you need to STRIP the variable to remove leading spaces if you do not want to count them.

PaigeMiller
Diamond | Level 26

Do you consider a character string of 003 to be 3 digits or 1 digit?

--
Paige Miller
NickK
Fluorite | Level 6
There's no leading 0s or blanks in this case.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 805 views
  • 1 like
  • 3 in conversation