Help using Base SAS procedures

Advance Filter "Begins With"

Accepted Solution Solved
Reply
Contributor
Posts: 22
Accepted Solution

Advance Filter "Begins With"

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?


Accepted Solutions
Solution
‎11-18-2013 01:20 PM
Super User
Posts: 17,963

Re: Advance Filter "Begins With"

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


All Replies
Super Contributor
Posts: 1,636

Re: Advance Filter "Begins With"

example:

data have;

input n;

cards;

20

30

;

data want;

  set have;

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

  proc print;run;

Solution
‎11-18-2013 01:20 PM
Super User
Posts: 17,963

Re: Advance Filter "Begins With"

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'

PROC Star
Posts: 1,570

Re: Advance Filter "Begins With"

[ Edited ]

 

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?

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 1707 views
  • 3 likes
  • 4 in conversation