DATA Step, Macro, Functions and more

Where and PDV

Reply
N/A
Posts: 0

Where and PDV

data A;
do i=1 to 10;
output;
end;
run;


data B;
set A(where=(i<8)) A;
where i>3;
run;


SAS help document says "A WHERE expression tests the condition before an observation is read into the PDV". But there are 14 observations in B. What happens in PDV?
Frequent Contributor
Posts: 106

Re: Where and PDV

Add dataset option IN= to your SET statement and enlighten us all. Somewhat like
[pre]
data b;
set a(in=a1 where=(i<8)) a(in=a2);
where i>3;
put (_n_ i a1 a2) (=);
run;
[/pre]
Super Contributor
Super Contributor
Posts: 3,174

Re: Where and PDV

Consider the possibilities:

- Learning opportunity....
- Self-discovery...
- Desk-checking SAS program code-path / logic...

Amazing how much information one can learn from a PUT (to the SAS log) or with a PUTLOG statement.

Scott Barry
SBBWorks, Inc.
Valued Guide
Posts: 2,174

Re: Where and PDV

clearly when you use a where clause in data set options, it doesn't use the conditions of the where statement . This causes a WARNING if A is read on the SET statement only with WHERE clauses[pre]25 data B;
26 set A(where=(i<8)) ;
27 where i>3;
WARNING: The WHERE statement cannot be applied to a data set on
the last SET/MERGE/UPDATE/MODIFY statement. Either
the data sets listed failed with open errors or they
already specify a WHERE data set option.
28 run;

NOTE: There were 7 observations read from the data set WORK.A.
WHERE i<8;
NOTE: The data set WORK.B has 7 [/pre] This is tested on SAS9.2
It may be different on your release.
Regular Contributor
Posts: 241

Re: Where and PDV

...

> SAS help document says "A WHERE expression tests the

> condition before an observation is read into the

> PDV".

...

It is also clearly documented here that:


"If you use both the WHERE= data set option and the WHERE statement in the same DATA step, SAS ignores the WHERE statement for data sets with the WHERE= data set option."
N/A
Posts: 0

Re: Where and PDV

"If you use both the WHERE= data set option and the WHERE statement in the same DATA step, SAS ignores the WHERE statement for data sets with the WHERE= data set option."



I get it. Thank you all.
Ask a Question
Discussion stats
  • 5 replies
  • 236 views
  • 0 likes
  • 5 in conversation