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

Trying to create dummy variables using arrays and I keep getting an 'array subscript out of range' error message. Can anyone help with what i'm doing wrong?

 

DATA WR16; SET final16;

Array race {10} R1_1-R1_10; Do i=1-10;

If race {i} = 'R1' then AIAN =1;

If race {i} = 'R2' then Asian =1;

If race {i} = 'R3' then Black =1;

If race {i} = 'R4' then NHPI =1;

If race {i} = 'R5' then White =1;

If race {i} = 'R9' then Other =1;

end;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Correction:  Do i=1 to 10;

 

DATA WR16; SET final16;

Array race {10} R1_1-R1_10; 

Do i=1 to 10;

If race {i} = 'R1' then AIAN =1;

If race {i} = 'R2' then Asian =1;

If race {i} = 'R3' then Black =1;

If race {i} = 'R4' then NHPI =1;

If race {i} = 'R5' then White =1;

If race {i} = 'R9' then Other =1;

end;

run;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

Correction:  Do i=1 to 10;

 

DATA WR16; SET final16;

Array race {10} R1_1-R1_10; 

Do i=1 to 10;

If race {i} = 'R1' then AIAN =1;

If race {i} = 'R2' then Asian =1;

If race {i} = 'R3' then Black =1;

If race {i} = 'R4' then NHPI =1;

If race {i} = 'R5' then White =1;

If race {i} = 'R9' then Other =1;

end;

run;

Vivv
Fluorite | Level 6

Thank you @novinosrin ,its amazing how such a tiny mistake in coding could matter a lot.

ballardw
Super User

You might consider instead of

If race {i} = 'R1' then AIAN =1;

using

AIAN = (race [I] = 'R1');

which will have 0 values when not true.

Then MEAN of AIAN  will be the decimal percentage of AIAN in the data set and you may find other uses as well.

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1319 views
  • 1 like
  • 3 in conversation