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.

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