Solved
Contributor
Posts: 35

# question regarding arrays

Hi,

I am wondering if it is possible to create elements in arrays. I have the following code. I believe _1 _2 _0 are created in this step. Also I am wondering whether "do over col" is same as  "do i = 1 to dim(col);

Could you please clarify.

data den;

set den ;

array col _1 _2 _0 _99 _999;

do over col;

if col=. then col=0;

end;

run;

Thanks,

Sam.

Accepted Solutions
Solution
‎01-03-2013 12:25 AM
PROC Star
Posts: 8,164

## Re: question regarding arrays

With a slight modification of your code you can see that the answers are both yes .. sort of.  First, try the following:

data den;

array col _1 _2 _0 _99 _999;

do over col;

counter+1;

col=counter;

end;

run;

As you can see after running the code, the five variables do indeed get created, and their assignments in the do over loop are clearly sequential.

I say "sort of" though, as you can only use do over with an implicitly defined array (i.e., where you don't define the number of elements in brackets in the array declaration) and, with implicitly defined arrays, you can't refer to them by number (e.g., col(1)).

All Replies
Solution
‎01-03-2013 12:25 AM
PROC Star
Posts: 8,164

## Re: question regarding arrays

With a slight modification of your code you can see that the answers are both yes .. sort of.  First, try the following:

data den;

array col _1 _2 _0 _99 _999;

do over col;

counter+1;

col=counter;

end;

run;

As you can see after running the code, the five variables do indeed get created, and their assignments in the do over loop are clearly sequential.

I say "sort of" though, as you can only use do over with an implicitly defined array (i.e., where you don't define the number of elements in brackets in the array declaration) and, with implicitly defined arrays, you can't refer to them by number (e.g., col(1)).

Contributor
Posts: 35

## Re: question regarding arrays

I understood clearly. Thank you very much Arthur.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
• 2 replies
• 212 views
• 4 likes
• 2 in conversation