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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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