home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / bit / listserv / sasl / 5145 < prev    next >
Encoding:
Text File  |  1992-11-24  |  3.5 KB  |  80 lines

  1. Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
  2. Path: sparky!uunet!paladin.american.edu!auvm!RTI.BITNET!FP$TJG
  3. X-VMS-To: RCCW21::IN%"VITRAI@NKI.BITNET"
  4. X-VMS-Cc: RCCW21::IN%"SAS-L@VTVM2.BITNET",FP$TJG
  5. MIME-version: 1.0
  6. Content-type: TEXT/PLAIN; CHARSET=US-ASCII
  7. Content-transfer-encoding: 7BIT
  8. Message-ID: <01GRHT0MYNAQ00004Q@RCCW21.RTI.ORG>
  9. Newsgroups: bit.listserv.sas-l
  10. Date:         Mon, 23 Nov 1992 14:32:05 -0500
  11. Reply-To:     TIM GABEL 541-7415 <FP$TJG@RTI.BITNET>
  12. Sender:       "SAS(r) Discussion" <SAS-L@UGA.BITNET>
  13. From:         TIM GABEL 541-7415 <FP$TJG@RTI.BITNET>
  14. Subject:      Re: problem with X{i}+1 type expressions
  15. Comments: To: VITRAI@NKI.BITNET
  16. Lines: 62
  17.  
  18. Jozsef,
  19.      When using your "short" assignment statement, you're telling SAS to
  20. assume a RETAIN statement for variables X1-X3.  That's why, when you don't
  21. execute for I=3, X1-X3 hold their values from the previous observation.
  22. The "complete" assignment statement does not imply a RETAIN for variables
  23. X1-X3.  Therefore, they're set to missing at the beginning of each observation
  24. and are not being initialized to zero or assigned a value for I=3.  By the way,
  25. using the "short" assignment statement also eliminates the need to initialize
  26. the values to zero.  If the results from the "complete" assignment are what
  27. you're after but you want to use the "short" assignment statement, I'd
  28. recommend the following:
  29.  
  30. ****************************** NEW SHORT *************************************
  31. data d2; set d1;
  32. array Xs {3} x1-x3;
  33. do j=1 to 3;
  34.    Xs{j}=.;    /* Need to reset to missing, since implied RETAIN statement */
  35.    if i ne 3 then Xs{j}+i;
  36. end;
  37. drop j;
  38.  
  39.  
  40. Good Luck.  Tim Gabel
  41.             Research Triangle Institute
  42.  
  43.  
  44. >Hi,
  45. >I ran into a possible error using the short form of an assignment with array.
  46. >Has anybody noticed this type of problem? Please have a look at it and tell me
  47. >what could be the cause behind it.
  48. >The problem is a very simple data step: counting occurances arrenged in arry.
  49. >The results of the use of the short and then the complet form of assignment is
  50. >located at right side of the program.
  51. >
  52. >****************************** SHORT ******************************************
  53. >data d1;                                           The SAS System
  54. >do i=1 to 5; output;end;                                  10:20 Monday
  55. >
  56. >data d2; set d1;                            OBS    I    X1    X2    X3
  57. >array Xs {3} x1-x3;
  58. >if i ne 3                                    1     1     1     1     1
  59. > then do;                                    2     2     2     2     2
  60. >   do j=1 to 3; Xs{j}=0; end;            ==> 3     3     2     2     2 <==
  61. >   do j=1 to 3; Xs{j}+i; end;                4     4     4     4     4
  62. >      end;                                   5     5     5     5     5
  63. >drop j;
  64. >proc print; run;
  65. >******************************** COMPLET **************************************
  66. >data d3; set d1;                                   The SAS System
  67. >array Xs {3} x1-x3;                                       10:20 Monday
  68. >if i ne 3
  69. > then do;                                   OBS    I    X1    X2    X3
  70. >   do j=1 to 3; Xs{j}=0; end;
  71. >   do j=1 to 3; Xs{j}=Xs{j}+i; end;          1     1     1     1     1
  72. >      end;                                   2     2     2     2     2
  73. >drop j;                                  ==> 3     3     .     .     . <==
  74. >proc print; run;                             4     4     4     4     4
  75. >                                             5     5     5     5     5
  76. >
  77. >*******************************************************************************
  78. >Thanks for your attention.
  79. >Jozsef
  80.