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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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