DATA Step, Macro, Functions and more

Quick search for a some value that can be in any tables column?

Accepted Solution Solved
Reply
Regular Contributor
Posts: 161
Accepted Solution

Quick search for a some value that can be in any tables column?

Hi All,

Is it possible find some value that can be in any tables column , without manually coding(macro etc.)?

For example, there is some table with 20 columns and I should make the query that shoud retutn all rows if any of the columns has some searching value...

Off cource I can make some workaround - f.e. macro that merge all columns into one character col and then just search for a needed value in this column, but may be there are some standard approcah in SAS for such cases?

Thanks!


Accepted Solutions
Solution
‎02-04-2013 10:32 AM
Occasional Contributor
Posts: 14

Re: Quick search for a some value that can be in any tables column?

Ron Cody and Jeff Smith's book Applied Statistics and the Sas Programming Language (Chapter 15 of the 4th edition) shares two arrays (one for character and one for numeric) intended to render the process you describe. 

View solution in original post


All Replies
Solution
‎02-04-2013 10:32 AM
Occasional Contributor
Posts: 14

Re: Quick search for a some value that can be in any tables column?

Ron Cody and Jeff Smith's book Applied Statistics and the Sas Programming Language (Chapter 15 of the 4th edition) shares two arrays (one for character and one for numeric) intended to render the process you describe. 

Regular Contributor
Posts: 161

Re: Quick search for a some value that can be in any tables column?

Posted in reply to Data_Detective_23219

Hi,

Thanks for the tip,  I believe that this solution actually what is needed, but I didn’t found some free version of the bookSmiley Happy, so if there are some “light” free version of the book and you have the link – please shareSmiley Happy

Anyway thanks, at least now I know the most optimal solution for the task.

Super User
Posts: 19,815

Re: Quick search for a some value that can be in any tables column?

If you're looking for a number or word that would be the entire variables value then you can use the whichc or whichn function coupled with the _numeric_ or _character_ shortcuts.  If the string can be only part of a variable then you need a different solution.

data want_numeric;

set sashelp.class;

if whichn(15, of _numeric_);

run;

data want_character;

set sashelp.class;

if whichc('F', of _character_);

run;

Regular Contributor
Posts: 161

Re: Quick search for a some value that can be in any tables column?

Hi Reeza,

Thanks for answer, your solution is very close to what is needed, but, as you supposed in your post, - I should make search in both char and numeric variable, and obviously char variables can have some numeric value etc.

But anyway thanks, I'm sure that I'll use these function in some future tasks.

Thanks!

🔒 This topic is solved and locked.

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

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