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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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