BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Angmar
Obsidian | Level 7

Hello,

 

I realised that the subset of data SAS creates when I use the WHERE statement in different lines is different.

For example, I often use:

DATA x (WHERE=(variable=1)

SET y

. . . 

 

But I recently used

DATA x;

SET y;

WHERE=variable=1;

 . . .

 

And the outputs were different. Would someone please explain to me why there is a difference?

 

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
mtnbikerjoshua
Obsidian | Level 7

Hi Angmar,

 

The difference there is that the first example, using where as a dataset option on the data statement, subsets the output dataset after all the processing in the data step has been done. The second example, using the where statement, subsets the input dataset(s) before all of the data processing. So, if the value of "variable" changes at all during the data step, the results of those two examples will be different.

 

Hope that explains it for you.

 

Joshua

View solution in original post

3 REPLIES 3
mtnbikerjoshua
Obsidian | Level 7

Hi Angmar,

 

The difference there is that the first example, using where as a dataset option on the data statement, subsets the output dataset after all the processing in the data step has been done. The second example, using the where statement, subsets the input dataset(s) before all of the data processing. So, if the value of "variable" changes at all during the data step, the results of those two examples will be different.

 

Hope that explains it for you.

 

Joshua

data_null__
Jade | Level 19
WHERE=variable=1;

When used in a data step is an assignment statement NOT a WHERE statement.  

 

Try using valid syntax.

WHERE variable = 1;

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
  • 3 replies
  • 1056 views
  • 1 like
  • 3 in conversation