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

Hello,

is there a simple  technique to find all records in a table where a specific value existe in one or more column?

For example, I want to retreive all records from table "tab" where we have "HL"

data tab;
input num1 num2 char1 $ num3 char2 $ char3 $;
datalines;
1 2 HL 3 HL X
4 5 AA 6 HL Y
7 8 EE 9 DD Z
;
run;

out put ==> 

1 2 HL 3 HL X
4 5 AA 6 HL Y

Thx,

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Since HL can only exist in character variables, we only search the character variables. I will use the WHICHC function to do the searching.

 

data want;
    set tab;
    if whichc('HL',of char:)>0 then output;
run;

Now, you made it easy, your character variable names all begin with the four letters char. If that's not the case in your real data, and you have character variables named GORILLA, SWAN, OCTOPUS, and so on, then instead of typing them all out, you could use something like this to search all character variables, regardless of their name:

 

if whichc('HL',of _character_)>0 then output;

 

--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Since HL can only exist in character variables, we only search the character variables. I will use the WHICHC function to do the searching.

 

data want;
    set tab;
    if whichc('HL',of char:)>0 then output;
run;

Now, you made it easy, your character variable names all begin with the four letters char. If that's not the case in your real data, and you have character variables named GORILLA, SWAN, OCTOPUS, and so on, then instead of typing them all out, you could use something like this to search all character variables, regardless of their name:

 

if whichc('HL',of _character_)>0 then output;

 

--
Paige Miller
viona
Calcite | Level 5
Thx a lot this is really helpful.
manojb
Calcite | Level 5

what if the value is a number and the variable is character. 

I have a situation where i should find a number ''4543" in nearly 150 variables. variables are mixed of numeric and char. 

could you please suggest

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 4445 views
  • 3 likes
  • 3 in conversation