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

I am trying to do an advance filter in a column I have named "Wages".  This column is made up of random numbers of dollars amounts in dollar20. format. 

I want to do a query were I get only the Wages that starts with the number 2.  I have tried many options, but none of then have worked for me.  I tried this formula but it didnt work either,  Wages LIKE '2%'

I got an error saying it cant be done because is not character formatted.   Any ideas?

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Assuming this is EG, which it sounds like you should post it in EG Forum

This would be a two step process in my opinion, 1, convert to character and then check if the first character is a 2. You can easily nest these functions though.

LinLin's code above could also be used in your query, but there are many other options, since it generates a conversion note.

substr(left(put(n, 8.)), 1, 1)='2'

View solution in original post

3 REPLIES 3
Linlin
Lapis Lazuli | Level 10

example:

data have;

input n;

cards;

20

30

;

data want;

  set have;

  if first(left(n))='2';

  proc print;run;

Reeza
Super User

Assuming this is EG, which it sounds like you should post it in EG Forum

This would be a two step process in my opinion, 1, convert to character and then check if the first character is a 2. You can easily nest these functions though.

LinLin's code above could also be used in your query, but there are many other options, since it generates a conversion note.

substr(left(put(n, 8.)), 1, 1)='2'

ChrisNZ
Tourmaline | Level 20

 

Or to make it short while avoiding notes in the log:

 

first(cats(n))='2'

 

or even shorter

 

cats(n)=:'2'

 

 

Edit:  Oops sorry I didn't see this was old. Why was it in the front page?

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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