BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
TPayne
Fluorite | Level 6

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;

1 ACCEPTED SOLUTION

Accepted Solutions
smijoss1
Quartz | Level 8

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;

View solution in original post

5 REPLIES 5
TPayne
Fluorite | Level 6

Thanks! Makes sense- I thought I had to tell it to do an iteration for each array listed! 

smijoss1
Quartz | Level 8

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;

Reeza
Super User

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;


 

FreelanceReinh
Jade | Level 19

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

  • "MISSING" if all 75 values are missing
  • "HD ONLY" if at least one of the values equals 1, but none equals 0
  • "MED ONLY" if at least one of the values equals 0, but none equals 1
  • "BOTH" in all other cases (i.e., if at least one of the values equals 0, and at least one equals 1 -- assuming that 0, 1 and . are the only possible values).

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1024 views
  • 0 likes
  • 5 in conversation