Programming 1 and 2

For questions related to SAS programming courses and case studies
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mlm155
Obsidian | Level 7

I tried a data step with two where statements and realised that only the second where condition is affecting the output - see sample code below:

 

data result_2where_conditions;
set class_birthdate;
where Registration = 'C';

where Age = 12;

run;

 

Can somebody shed some light on why this happens?

Thanks heaps.

 



1 ACCEPTED SOLUTION
4 REPLIES 4
Astounding
PROC Star
Alternatively, add the keyword SAME to the second WHERE statement:

where same and age=12;
Kurt_Bremser
Super User

While this is valid and works, I would not even teach it, as sooner or later someone comes up with

where condition1;
/* 1000 lines of data step code */
where same and condition2;
/* another 1000 lines of data step code */
where same and condition3;

which is horrible to debug and maintain.

Astounding
PROC Star
I agree, for simple sets of conditions. For complex sets of conditions, it can be easier to read the "same and" version.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

LIBNAME 101

Follow along as SAS technical trainer Dominique Weatherspoon expertly answers all your questions about SAS Libraries.

Find more tutorials on the SAS Users YouTube channel.

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