LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (November 2010, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
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:
Comments: To: SUBSCRIBE SAS-L Dan <deniseyu001@GMAIL.COM>
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;


Back to: Top of message | Previous page | Main SAS-L page