Hi Irin,
Jim is absolutely correct. You need to adjust the bounds of the
dimensions of the array because variable Q609 (Gainweight) turned out
to have a value 0. For most arrays, 1 is a convenient lower bound;
thus, you do not need to specify the lower and upper bounds. However,
specifying lower and upper bounds is useful when the array dimensions
have a convenient beginning point other than 1, which in this case is
0. (Source: SAS Help and Documentation for Arrays).
So, incorporating Jim's suggestion, here's the updated code.
HTH,
Florio
Data hfbc65IntGain ;
Length ID $ 3 Q6709 $ 20 ;
Infile Cards MISSOVER;
Input Id $ Q6709 $ ;
if Q6709 = " " THEN Q6709 = "0";
Cards4 ;
m1 2;4;7;8;6
m2 2;3
m3 1;7;8
m4 5;2
m5
;;;;
Run ;
data hfbc65IntGainneed (drop = i j);
set hfbc65IntGain;
array s(0:8) _temporary_;
array r(0:8) r0-r8;
do i = 1 by 1 while(scan(Q6709,i,';') ne "");
s(i)=scan(Q6709,i,';');
do j = 0 to 8;
if s(i) = j then r(j)=1;
if r(j) = . then r(j)=0;
end;
end;
run;
proc freq data = hfbc65IntGainneed;
table r0-r8;
run;
At 09:02 AM 11/1/2006, Jim Groeneveld wrote:
>Hi Irin,
>
>Have a look at the dumped values below the error: j=0, which originates from
>line 53, where you start with j=0. 0 is not a valid index for an array
>element unless the range of indices has been defined at the time of array
>definition, e.g. instead of [array r(9) r0-r8;] state:
>array r(0:8) r0-r8;
>
>In SAS array elements start with the number 1, unlike in C for example.
>
>Regards - Jim.
>--
>Jim Groeneveld, Netherlands
>Statistician, SAS consultant
>home.hccnet.nl/jim.groeneveld
>
>
>On Wed, 1 Nov 2006 05:46:01 -0800, Irin later <irinfigvam@YAHOO.COM> wrote:
>
> >Florio, thank you for the response. I tried to run it and get the following
>Error message,
> > which I do not understand. The thing is that Q6709 (gainweight) has a
>value "2"...then why it does not work?
> >
> > Thank you in advance,
> >
> > Irin
> >
> >
> > 42 data hfbc65IntGain;
> > 43 SET hfbc65Intout;
> > 44 if Q6709 = " " THEN Q6709 = "0";
> > 45 run;
> > NOTE: There were 375 observations read from the data set
> WORK.HFBC65INTOUT.
> > NOTE: The data set WORK.HFBC65INTGAIN has 375 observations and
> 28 variables.
> > NOTE: DATA statement used:
> > real time 0.01 seconds
> > cpu time 0.01 seconds
> >
> > 46
> > 47 data hfbc65IntGainneed (drop = i j);
> > 48 set hfbc65IntGain;
> > 49 array s(9) _temporary_;
> > 50 array r(9) r0-r8;
> > 51 do i = 1 by 1 while(scan(Q6709,i,';') ne "");
> > 52 s(i)=scan(Q6709,i,';');
> > 53 do j = 0 to 8;
> > 54 if s(i) = j then r(j)=1;
> > 55 if r(j) = . then r(j)=0;
> > 56 end;
> > 57 end;
> > 58 run;
> > NOTE: Character values have been converted to numeric values at the
>places given by:
> > (Line):(Column).
> > 52:2
> > ERROR: Array subscript out of range at line 55 column 6.
> > PerID=200608 SRID=2342933 Date=11AUG2006:00:00:00 WebResponse= Q6694=5
>Q6695=4 Q6696=5 Q6697=4
> > Q6698=5 Q6699=5 Q6700=4 Q6701=5 Q6702=5 Q6703=5 Q6704=4 Q6705=4 Q6706=5
>Q6707=5 Q6708=1 Q6709=2
> > Q6710=4 Q6711=2;3;4;5;6;7 Q6616=4 Q1156=5 Q1157=1 Q6618=51 Q6619=1
>Q6665=20 r0=. r1=. r2=. r3=.
> > r4=. r5=. r6=. r7=. r8=. i=1 j=0 _ERROR_=1 _N_=1
> >
> >
> >Florio Arguillas <foa2@CORNELL.EDU> wrote:
> > Hi Irina,
> >
> >Here's a code. The approach taken is to create 8 variables -- one for
> >each value of response. Variable R1 will take a value of 1 if the value 1
> >is found in the variable GAINWEIGHT and 0 if not found. R2 will take a
> >value of 1 if the value 2 is found in the variable GAINWEIGHT and 0 if not
> >found. And so on...
> >
> >HTH,
> >
> >Florio Arguillas
> >Consultant Advisor
> >Cornell Institute for Social and Economic Research
> >
> >P.s. Here's the code;
> >
> >data need (drop = i j);
> >set have;
> >array s(8) _temporary_;
> >array r(8) r1-r8;
> >do i = 1 by 1 while(scan(gainweight,i,';') ne "");
> >s(i)=scan(gainweight,i,';');
> >do j = 1 to 8;
> >if s(i) = j then r(j)=1;
> >if r(j) = . then r(j)=0;
> >end;
> >end;
> >run;
> >
> >proc freq data = have;
> >table r1-r8;
> >run;
> >
> >
> >
> >
> >
> >
> >On Tue, 31 Oct 2006 17:32:10 -0800, Irin later
> >wrote:
> >
> >>I have a survey with a combinations of patients' responds (char data
> >type ), seperated ny semicolon
> >>
> >> id gainweight
> >> m1 2;4;7;8;6
> >> m2 2;3
> >> m3 1;7;8
> >> m4 5;2
> >>
> >> Members respond in different combinations. The purpose is to calculate
> >how many times respond "1" "2" "3" "4"....."8" (max) occurs in order to
> >generate a frequency of occurence.
> >> For ex, 1(5%)
> >> 2(30%)
> >> 3(10%)
> >> 4(15%)
> >> 5(20%)
> >> 6(5%)
> >> 7(10%)
> >> 8(5%)
> >>
> >> How can I code it?
> >>
> >> Can you give me a hand?
> >>
> >> Thank You !
> >>
> >> Irina
> >>
> >>
> >>---------------------------------
> >> Check out the New Yahoo! Mail - Fire up a more powerful email and get
> >things done faster.
> >
> >
> >
> >---------------------------------
> >Cheap Talk? Check out Yahoo! Messenger's low PC-to-Phone call rates.
|