Thank you all for your help. Here are a couple examples of what I am talking about. The simplest example is the following. data output; if new_var = . then put "new_var exists and was never declared"; run; A more complicated example comes from a problem I was trying to solve involving a sohisticated merge. Imagine we have a dataset with babies and the days they were born. We also have a dataset with doctors containing flags for the days they worked at the hospital. I wanted to create a dataset that would list all the possible baby-doctor combinations such that the doctor might have delivered the baby. ie. The doctor worked on the baby's birthday. Below is the solution which I adapted from code someone posted online in response to this question. data babies; input baby_name $ birth_day birth_day_name $; datalines; Jake 1 day1 Sonny 4 day4 North 5 day5 Apple 6 day6 ; run; data doctors; input DrLastname $ day1 day2 day3 day4 day5 day6; datalines; Jones 1 0 0 1 1 1 Lewis 1 1 1 0 0 1 Smith 0 1 1 1 0 1 ; run; data babies_doctors_array; array drnames[3] $10 _temporary_; array drdays[3,6] _temporary_; /* load doctors dataset into temp arrays */ if _n_=1 then do i = 1 to nobs_doctors; set doctors point=i nobs=nobs_doctors; array days day1-day6; drnames=DrLastname; do j = 1 to dim(days); drdays[i,j]=days ; end; end; /* go through babies to find doctors that worked on thei birthday*/ set babies; do k = 1 to nobs_doctors; if drdays[k,birth_day]=1 then do; babys_doctor = drnames ; output; end; end; keep baby_name birth_day babys_doctor; run; proc print data=babies_doctors_array; run; The variable nobs_doctors is used in the do loop before the set statement in which it is declared. The most recent case of this I've encountered that prompted me to start this discussion looks like it is a coding error to me. Here is a really stripped down version of the code. data raw; format dos date9.; input id dos mmddyy. comp1 comp2 comp3; datalines; 1 121299 1 0 0 1 121299 0 1 0 1 101103 0 1 0 2 030400 1 1 0 2 030400 0 0 0 2 040400 0 0 1 3 041190 0 1 0 4 092090 0 0 1 4 051589 0 1 0 5 040300 0 0 0 5 071710 1 0 0 5 070899 0 1 0 6 030299 0 1 0 7 121200 1 0 0 ; run; proc print data=raw;run; proc sort data=raw; by id dos; run; data fin; set raw; by id dos; /* not sure about using compsum before it is defined */ if compsum = 0 then no_comps = 1; compsum = sum(comp1, comp2, comp3); run; This just looks like a mistake to me and illustrates why I think this behavior is dangerous. It makes this kind of coding error hard to catch. Thanks again for all your help. -Adam
... View more