super wired, I actually then converted the income_dx to an income_dx2 and assign the 2nd one numeric type, the re-ran the loop, and the probem
moved down to line (plz see original) coding2(ETHG_dx)=1;
I've got a great update. Even it's not perfect yet. However, now I am able to have the nested loop completed
EXCEPT!!
it wouldn't print out the missing element for me.
So, ok the income_dx are all going to be my binary variables.
so I have 6 columbs represent salary1 salary2 ....salary6 but just not the "missing", ok I changed the name to salary9, didn't work, and ok changed it again to salary7...................didn't work,either.
here is the error for my log.
ERROR: Array subscript out of range at line ~ column ~. and that's it. None of my errors have rulers or something.
which is this line here, coding4(k)=0; (???????)
Didn't I tell SAS PLEASE do 1 to 7?
What happened makes it just give me 6 columns (binary dummies variables)?
Your earlier post said the income_dx values were 1,2,3,4,5,6, and 9
If you want to do coding4(income_dx) = 1;, then that is going to put something in coding(9) at some point.
Have you got somewhere for sas to put it?
Go back to declaring your array as salary1-salary10 and there will be a variable to store for coding(9).
Then you also need to make sure that you are looking at all of the values when you are retrieving/initialising the values i.e. do k=1 to 10; NOT do k=1 to 7;
Does that make sense?
set stdff;
array coding2 {*} agroup_1-agroup_6;
do i=1 to 6;
coding2(i)=0; /*i isn't used past this point but you're repeating the loop 6 times for what reason?????*/
array coding3 {*} boys girls notdisclose nodata;
do j=1 to 4;
coding3(j)=0; /*j isn't used past this point but you're repeating the loop 4 times for what reason?????*/
array coding4 {*} salary1-salary6 salary7;
do k=1 to 7;
coding4(k)=0;
/*k isn't used past this point but you're repeating the loop 7 times for what reason?????*/
end;
coding4(income_dx)=1; <-------------------------------Error Happens Here!! Need help!!
end;
coding3(gndr_dx)=1;
end;
coding2(ETHG_dx)=1;
drop i j k;
run;
Your loops and code make no sense to me at all. And if you've define an array of 7 elements but call it with 9 then it's clearly out of range. Re-think whatever you're trying to do and give it another go...
It sounds like you're looking for this:
coding4(min(7, income_dx))=1;
That way, when income_dx is 9, the MIN function returns 7 and the statement changes the 7th element of the array.
Sensible?
Thank you very much. I will try it. Happy holidays all.
min(7,income_dx) - that's an Astoundingly good suggestion. I like it.
I have another alternative, though - use a format to map the value of income_dx to an array index.
With a format you could catch values for income_dx that are not in 1,2,3,4,5,6,9 and assign them to another array index for data "errors". A format would also let you convert the character income_dx to a number without creating another variable.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.