|
Mohammad -
The answer is simple. When a data step compiles SAS sets up a program
data vector (PDV). There is only one PDV for the data step, no matter how
many datasets are being read or written. All the variables in the incoming
dataset(s) and any variables created in the data step are in the PDV.
Unless you specify otherwise, with KEEP or DROP, when datasets are written
out, all the variables in the PDV are written to all output datasets.
To get what you expected, add a DROP option to your two datasets:
data a(drop=z) b(drop=y);
Pete Lund
WA State Caseload Forecast Council
(360) 902-0086 voice
(360) 902-0084 fax
peter.lund@cfc.wa.gov
-----Original Message-----
From: Mo Uddin-M [mailto:uddin.m@PG.COM]
Sent: Thursday, March 02, 2000 11:17 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Fundamental Question
Hi Folks,
I have a very fundamental question. If I run the following code:
data k;
do i=1 to 10;
x=ranuni(100);
output;
end;
data a b;
set k;
if i in (2, 4, 6) then do;
y=x;
output a;
end;
else if i in (9, 10) then do;
z=x;
output b;
end;
proc print data=a;
proc print data=b;
run;
I get these two sets for data a & b;
OBS I X Y Z
1 2 0.00887 0.00887 .
2 4 0.93986 0.93986 .
3 6 0.92773 0.92773 .
OBS I X Y Z
1 9 0.97940 . 0.97940
2 10 0.65666 . 0.65666
My question is why variable Z in data a and Y in data b.
I would appreciate an explanation for this.
Thanks in advance.
Mohammad
|