Date: Tue, 17 Oct 2000 03:20:44 -0400
Reply-To: Gerhard Hellriegel <ghellrieg@T-ONLINE.DE>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Gerhard Hellriegel <ghellrieg@T-ONLINE.DE>
Subject: Re: keep= vs. Keep statement
On Tue, 17 Oct 2000 07:14:25 +0100, Roland <roland.rashleigh-
berry@VIRGIN.NET> wrote:
>paula wrote:
>>
>> My code looks like this
>> [
>> data set1 set2;
>>
>> infile.......;
>> input A $1 B 2.2 C 3.2;/*A can only take a or b*/
>> if A = 'a' then do;
>> x=b+c;
>> keep a x;
>> output set1;
>> end;
>> if A = 'b' then do;
>> y=b+c;
>> keep a y;
>> output set2;
>> end;
>>
>> ]
>>
>> I simply want to keep only TWO variables in the resulting subsets. But
the
>> result is set1 also retains y flooded with missing values, while set2 has
>> variable included full of missing values as well.
>>
>> I know the solution is to use Keep= in the Data statement when
'declaring'
>> the two data sets. Could somebody explain why my original code does not
>> work?
>>
>> Thanks.
>>
>> Sincerely
>>
>> Paula D
>
>Yes, because "keep" statements in datasteps are not conditionally
>executed. In other words, by virtue of the fact that they are there then
>they take effect. The same goes for "drop" and "retain" and "length".
>
>Also there is no way you can have one keep statement associated with one
>dateset while another with another datastep unless you use the "keep="
>against the datasets themselves.
>
>Roland
...but that is very easy:
data set1(keep=a x) set2(keep=a y);
......
thats all.
|