i have a dataset of dummy variables (0,1, .) that I want to use to determine the value of a new variable, "source". I have the below array and cannot figure out why it is saying array out of range. any suggestions are appreciated.
DATA DATA.SOURCE_CHECK4 (DROP=I);
SET DATA.SOURCE_CHECK3;
FORMAT SOURCE $10.;
ARRAY DTP [8] DTPSRC1-DTPSRC8;
ARRAY OPV [8] OPVSRC1-OPVSRC8;
ARRAY MMR [8] MMRSRC1-MMRSRC8;
ARRAY HIB [6] HIBSRC1-HIBSRC6;
ARRAY HBV [7] HBVSRC2-HBVSRC8; /*GETTING RID OF BIRTHDOSE HBV*/
ARRAY VAX [8] VAXSRC1-VAXSRC8;
ARRAY STP [8] STPSRC1-STPSRC8;
ARRAY FLU [8] FLUSRC1-FLUSRC8;
ARRAY HAV [8] HAVSRC1-HAVSRC8;
ARRAY RTV [6] RTVSRC1-RTVSRC6;
DO I= 1 TO 75;
IF (DTP[I] = 1 OR DTP[I]=.) AND (OPV[I] = 1 OR OPV[I]=.) AND (MMR[I] = 1 OR MMR[I]=.) AND
(HIB[I] = 1 OR HIB[I]=.) AND (HBV[I] = 1 OR HBV[I]=.) AND (VAX[I] = 1 OR VAX[I]=.) AND
(STP[I] = 1 OR STP[I]=.) AND (FLU[I] = 1 OR FLU[I]=.) AND (HAV[I] = 1 OR HAV[I]=.) AND
(RTV[I] = 1 OR RTV[I]=.) THEN SOURCE="HD ONLY";
ELSE IF
(DTP[I] = 0 OR DTP[I]=.) AND (OPV[I] = 0 OR OPV[I]=.) AND (MMR[I] = 0 OR MMR[I]=.) AND
(HIB[I] = 0 OR HIB[I]=.) AND (HBV[I] = 0 OR HBV[I]=.) AND (VAX[I] = 0 OR VAX[I]=.) AND
(STP[I] = 0 OR STP[I]=.) AND (FLU[I] = 0 OR FLU[I]=.) AND (HAV[I] = 0 OR HAV[I]=.) AND
(RTV[I] = 0 OR RTV[I]=.) THEN SOURCE="MED ONLY";
ELSE IF
(DTP[I]=.) AND (OPV[I]=.) AND (MMR[I]=.) AND
(HIB[I]=.) AND (HBV[I]=.) AND (VAX[I]=.) AND
(STP[I]=.) AND (FLU[I]=.) AND (HAV[I]=.) AND
(RTV[I]=.) THEN SOURCE="MISSING";
ELSE SOURCE="BOTH";
END;
RUN;
your are defining DTP with 8 elements in it (ARRAY DTP [8] DTPSRC1-DTPSRC8;)
The way you have written do loop it is expecting 75 elements. DO I= 1 TO 75;
No miracle. The maximum size of any array is 8, while you try to iterate i up to 75.
Thanks! Makes sense- I thought I had to tell it to do an iteration for each array listed!
your are defining DTP with 8 elements in it (ARRAY DTP [8] DTPSRC1-DTPSRC8;)
The way you have written do loop it is expecting 75 elements. DO I= 1 TO 75;
i goes to 75 but each of your arrays only has 7 or 8 elements.
I don't know what you think is happening, but it's not correct.
@TPayne wrote:
i have a dataset of dummy variables (0,1, .) that I want to use to determine the value of a new variable, "source". I have the below array and cannot figure out why it is saying array out of range. any suggestions are appreciated.
DATA DATA.SOURCE_CHECK4 (DROP=I);
SET DATA.SOURCE_CHECK3;
FORMAT SOURCE $10.;
ARRAY DTP [8] DTPSRC1-DTPSRC8;
ARRAY OPV [8] OPVSRC1-OPVSRC8;
ARRAY MMR [8] MMRSRC1-MMRSRC8;
ARRAY HIB [6] HIBSRC1-HIBSRC6;
ARRAY HBV [7] HBVSRC2-HBVSRC8; /*GETTING RID OF BIRTHDOSE HBV*/
ARRAY VAX [8] VAXSRC1-VAXSRC8;
ARRAY STP [8] STPSRC1-STPSRC8;
ARRAY FLU [8] FLUSRC1-FLUSRC8;
ARRAY HAV [8] HAVSRC1-HAVSRC8;
ARRAY RTV [6] RTVSRC1-RTVSRC6;
DO I= 1 TO 75;
IF (DTP[I] = 1 OR DTP[I]=.) AND (OPV[I] = 1 OR OPV[I]=.) AND (MMR[I] = 1 OR MMR[I]=.) AND
(HIB[I] = 1 OR HIB[I]=.) AND (HBV[I] = 1 OR HBV[I]=.) AND (VAX[I] = 1 OR VAX[I]=.) AND
(STP[I] = 1 OR STP[I]=.) AND (FLU[I] = 1 OR FLU[I]=.) AND (HAV[I] = 1 OR HAV[I]=.) AND
(RTV[I] = 1 OR RTV[I]=.) THEN SOURCE="HD ONLY";
ELSE IF
(DTP[I] = 0 OR DTP[I]=.) AND (OPV[I] = 0 OR OPV[I]=.) AND (MMR[I] = 0 OR MMR[I]=.) AND
(HIB[I] = 0 OR HIB[I]=.) AND (HBV[I] = 0 OR HBV[I]=.) AND (VAX[I] = 0 OR VAX[I]=.) AND
(STP[I] = 0 OR STP[I]=.) AND (FLU[I] = 0 OR FLU[I]=.) AND (HAV[I] = 0 OR HAV[I]=.) AND
(RTV[I] = 0 OR RTV[I]=.) THEN SOURCE="MED ONLY";
ELSE IF
(DTP[I]=.) AND (OPV[I]=.) AND (MMR[I]=.) AND
(HIB[I]=.) AND (HBV[I]=.) AND (VAX[I]=.) AND
(STP[I]=.) AND (FLU[I]=.) AND (HAV[I]=.) AND
(RTV[I]=.) THEN SOURCE="MISSING";
ELSE SOURCE="BOTH";
END;
RUN;
Hi @TPayne,
I'm not sure about the expected result of your data step (note that variable SOURCE would be overwritten in every iteration of the DO loop), but maybe it's similar to what the data step below creates (or you can adapt this step accordingly):
data want;
array x[*] DTPSRC1-DTPSRC8 OPVSRC1-OPVSRC8 MMRSRC1-MMRSRC8 HIBSRC1-HIBSRC6 HBVSRC2-HBVSRC8
VAXSRC1-VAXSRC8 STPSRC1-STPSRC8 FLUSRC1-FLUSRC8 HAVSRC1-HAVSRC8 RTVSRC1-RTVSRC6;
set data.source_check3;
length source $10;
if n(of x[*])=0 then source="MISSING";
else if 1 in x & 0 ~in x then source="HD ONLY";
else if 0 in x & 1 ~in x then source="MED ONLY";
else source="BOTH";
run;
The logic used here: Variable SOURCE will be
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: