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 (August 1998, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Sun, 2 Aug 1998 14:55:18 +0200
Reply-To:     martin.gregory@bigfoot.com
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         Martin Gregory <martin@DJOUCE.MANNHEIM-NETZ.DE>
Subject:      Re: Bug or Feature With No Obvious Use?
Comments: To: kjb@GA.UNC.EDU
In-Reply-To:  message from Keith Brown on Fri, 31 Jul 1998 14:06:15 -0500
Content-Type: text/plain; charset=US-ASCII

Hi Keith,

Keith> I recently ran across (got bitten by, actually) the Keith> situation illustrated below. I had the same variable (N1) Keith> in two different datasets. In one, it was character; in Keith> the other, it was numeric. I renamed the character version Keith> to be consistent with a character variable in the other Keith> dataset, and recomputed the numeric variable when it was Keith> missing (or so I thought). Somehow, the numeric variable Keith> was retained from the first observation in dataset B. Does Keith> anybody know where this "feature" is documented, if at all? Keith> I'd like to think that, if it's part of SAS, there's a Keith> reason for it, but danged if I can imagine a situation Keith> where this is what I want to happen. Thanks for any Keith> pointers,

The answer lies in understanding when the dataset data vector is initialised.The initialisation of the data vector is done when an observation is read from the dataset, but my understanding is that only the variables from the dataset being read are initialised. It also seems that in a simple concatenating SET, the variables from the first dataset are initialised during the execution of the dataset subsequent to the last observation being read from that dataset.

Your variable N1 is only on dataset A, the first one to be read. You explicitly set N1 after the first obs has been read from B, and this never gets initialised again because no more obs are read from A. Thus your condition "n1=." is only true on the first obs from B.

You can see what happens by putting the values before and after the set statement (I've dropped some of the lines for clarity):

49 data c; 50 put '++> ' _all_ ; 51 set a 52 b(rename=(n1=c1)); 53 put '--> ' _all_ ; 54 if n1=. then n2=input(c1,4.2); 55 if n1=. then n1=input(c1,4.2); 56 run;

++> ID= C1= N1=. N2=. _ERROR_=0 _N_=1 --> ID=A1 C1=0100 N1=1 N2=. _ERROR_=0 _N_=1 ++> ID=A1 C1=0100 N1=1 N2=. _ERROR_=0 _N_=2 --> ID=A2 C1=0200 N1=2 N2=. _ERROR_=0 _N_=2 [...] --> ID=A9 C1=0900 N1=9 N2=. _ERROR_=0 _N_=9 ++> ID=A9 C1=0900 N1=9 N2=. _ERROR_=0 _N_=10 --> ID=B1 C1=0100 N1=. N2=. _ERROR_=0 _N_=10 ++> ID=B1 C1=0100 N1=1 N2=. _ERROR_=0 _N_=11 --> ID=B2 C1=0200 N1=1 N2=. _ERROR_=0 _N_=11 ++> ID=B2 C1=0200 N1=1 N2=. _ERROR_=0 _N_=12 [...] NOTE: The data set WORK.C has 18 observations and 4 variables. NOTE: DATA statement used: real time 0.17 seconds cpu time 0.02 seconds

cheers, Martin -- Martin Gregory Steubenstr. 52-54 martin@djouce.mannheim-netz.de D-69121 Heidelberg


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