Date: Tue, 9 Nov 2010 04:43:24 -0500
Reply-To: Søren Lassen <s.lassen@POST.TELE.DK>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Søren Lassen <s.lassen@POST.TELE.DK>
Subject: Re: Add more records:
Content-Type: text/plain; charset=ISO-8859-1
I think that what you want to do is this:
1. generate a dataset with all key values present, and all data values
set to 0:
data keys;
retain lab 1 order 1 cnt1-cnt3 0;
do order=1 to 3;
output;
end;
run;
2. Use your observational data to update your key data:
data have ;
input lab order cnt1 cnt2 cnt3 ;
datalines;
1 1 . 1 .
1 2 . 1 1
;
run;
Data want;
update keys have;
by lab order;
run;
The point of using UPDATE rather than MERGE is that existing values
(zeroes) are not overwritten by missing values.
Regards,
Søren
On Mon, 8 Nov 2010 12:16:57 -0500, SUBSCRIBE SAS-L Dan
<deniseyu001@GMAIL.COM> wrote:
>Hi. SAS_Lers:
>
>Please help me with the following code. Also could any one point out what
>I have done wrong? I might have a misunderstanding on some basic SAS
>conceptions, like Set, Output, Do loop. Thanks for the help. Dan
>
>Below is the code:
>
>data have ;
> input lab order cnt1 cnt2 cnt3 ;
> datalines;
> 1 1 . 1 .
> 1 2 . 1 1
> ;
> run;
>
> data want ;
> input lab order cnt1 cnt2 cnt3 ;
> datalines;
> 1 1 0 1 0
> 1 2 0 1 1
> 1 3 0 0 0
> ;
> run;
>
>data mytry ;
> set have ;
> array cntary (3) cnt1-cnt3;
> do i=1 to 3 ;
> if order=i then do ;
> do i=1 to 3 ;
> if cntary(i)=. then cntary(i)=0 ;
> end ;
> end ;
> else do ;
> do i=1 to 3 ;
> cntary(i)=0 ;
> end ;
> end ;
> output ;
> end ;
>run;