renaming a set of variables in SAS with DO loop

5.9k views Asked by At

I've been trying to rename a set of variables from a scale using arrays and DO loops, but without success. This seems like a very simple task. Any advice on where I'm going wrong?

ARRAY ATRSS (i) ATRSS_1  ATRSS_12 ATRSS_13 ATRSS_25 ATRSS_29 ATRSS_30 ATRSS_32 ATRSS_33 ATRSS_35 ATRSS_36;;
Array DIS (10) $ DIS1-DIS10; 

DO i = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10;
    DIS (i) = ATRSS(i);
END;

I get the error: Mixing of implicit and explicit array subscripting is not allowed.

Thanks!

1

There are 1 answers

0
Joe On BEST ANSWER

array atrss atrss_1 ... ;

Remove the (i) from the first line and you're fine.

I would note that you're not renaming, per se - you can't do a rename that way - but of course it accomplishes the same goal.

You can improve this further, although it works okay as is:

array atrss atrss_1 atrss_12 atrss_13 atrss_25 atrss_29 atrss_30 atrss_32 atrss_33 atrss-35 atrss_36;
array dis(10);

do i = 1 to dim(atrss);
 dis[i] = atrss[i];
end;

That makes it slightly more flexible, if you change the number of elements in atrss. do i = 1 to 10; is also acceptable - much easier than spelling them each out, anyway.