BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

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
Onyx | Level 15

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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 22156 views
  • 10 likes
  • 5 in conversation