X-VMS-To: RCCW21::IN%"VITRAI@NKI.BITNET"
X-VMS-Cc: RCCW21::IN%"SAS-L@VTVM2.BITNET",FP$TJG
MIME-version: 1.0
Content-type: TEXT/PLAIN; CHARSET=US-ASCII
Content-transfer-encoding: 7BIT
Newsgroups: bit.listserv.sas-l
Date:         Mon, 23 Nov 1992 14:32:05 -0500
Reply-To:     TIM GABEL 541-7415 <FP$TJG@RTI.BITNET>
From:         TIM GABEL 541-7415 <FP$TJG@RTI.BITNET>
Subject:      Re: problem with X{i}+1 type expressions
Comments: To: VITRAI@NKI.BITNET

Jozsef,
     When using your "short" assignment statement, you're telling SAS to
assume a RETAIN statement for variables X1-X3.  That's why, when you don't
execute for I=3, X1-X3 hold their values from the previous observation.
The "complete" assignment statement does not imply a RETAIN for variables
X1-X3.  Therefore, they're set to missing at the beginning of each observation
and are not being initialized to zero or assigned a value for I=3.  By the way,
using the "short" assignment statement also eliminates the need to initialize
the values to zero.  If the results from the "complete" assignment are what
you're after but you want to use the "short" assignment statement, I'd
recommend the following:

****************************** NEW SHORT *************************************
data d2; set d1;
array Xs {3} x1-x3;
do j=1 to 3;
   Xs{j}=.;    /* Need to reset to missing, since implied RETAIN statement */
   if i ne 3 then Xs{j}+i;
end;
drop j;


Good Luck.  Tim Gabel
            Research Triangle Institute


>Hi,
>I ran into a possible error using the short form of an assignment with array.
>Has anybody noticed this type of problem? Please have a look at it and tell me
>what could be the cause behind it.
>The problem is a very simple data step: counting occurances arrenged in arry.
>The results of the use of the short and then the complet form of assignment is
>located at right side of the program.
>
>****************************** SHORT ******************************************
>data d1;                                           The SAS System
>do i=1 to 5; output;end;                                  10:20 Monday
>
>data d2; set d1;                            OBS    I    X1    X2    X3
>array Xs {3} x1-x3;
>if i ne 3                                    1     1     1     1     1
> then do;                                    2     2     2     2     2
>   do j=1 to 3; Xs{j}=0; end;            ==> 3     3     2     2     2 <==
>   do j=1 to 3; Xs{j}+i; end;                4     4     4     4     4
>      end;                                   5     5     5     5     5
>drop j;
>proc print; run;
>******************************** COMPLET **************************************
>data d3; set d1;                                   The SAS System
>array Xs {3} x1-x3;                                       10:20 Monday
>if i ne 3
> then do;                                   OBS    I    X1    X2    X3
>   do j=1 to 3; Xs{j}=0; end;
>   do j=1 to 3; Xs{j}=Xs{j}+i; end;          1     1     1     1     1
>      end;                                   2     2     2     2     2
>drop j;                                  ==> 3     3     .     .     . <==
>proc print; run;                             4     4     4     4     4
>                                             5     5     5     5     5
>
>*******************************************************************************
>Thanks for your attention.
>Jozsef
Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU