BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

Hello

May anyone explain why in the following query  we get 5 rows.

The condition is :

where Gender="M";
where age>25;

Does it mean that the query is taking Males AND age>25?

In the result I see also Female.

Thanks

Yuli

 

Data Raw_tbl;
input name $ Gender $ age  ;
cards;
Anna F 23
Ben M 25
Bob M 21
Brian M 27
Edward M 26
Emma F 32
Joe M 34
Sam F 32
Tom M 24
;
run;


data  tbl2;
set Raw_tbl;
where Gender="M";
where age>25;
run;
5 REPLIES 5
SASKiwi
PROC Star

In your example the second WHERE overwrites the first one. If you want both to be used (the equivalent of using an AND between them) do this:

 

data  tbl2;
set Raw_tbl;
where Gender="M";
where also age>25;
run;
Reeza
Super User

Always check your log. 

 

5772F2AD-8D19-4C16-B22D-654B3B75E45B.jpeg

 

If you do want both, add an SAME AND after the second WHERE, but before age. 

 

Where same and age>25;

 


@Ronein wrote:

Hello

May anyone explain why in the following query  we get 5 rows.

The condition is :

where Gender="M";
where age>25;

Does it mean that the query is taking Males AND age>25?

In the result I see also Female.

Thanks

Yuli

 

Data Raw_tbl;
input name $ Gender $ age  ;
cards;
Anna F 23
Ben M 25
Bob M 21
Brian M 27
Edward M 26
Emma F 32
Joe M 34
Sam F 32
Tom M 24
;
run;


data  tbl2;
set Raw_tbl;
where Gender="M";
where age>25;
run;

 

Ronein
Meteorite | Level 14

As I see there are 2 equivalent way:

where also age>25;
where same age>25;

 Is there a difference between "SAME"  and "ALSO"?

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Use logical operands in your where clause:

where <condition> and/or <condition> and/or <condition>...;

I have never heard of, nor seen where also or where same being used.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 5 replies
  • 21270 views
  • 10 likes
  • 5 in conversation