Jebediah15
Jebediah15

Reputation: 794

Illegal reference to array

The first code seems to work, but the second is saying there is an illegal reference to array in the log. I am trying to assign new values to specific quarters, which are separate variables, without overriding the previous quarter values. So, the second example will change values for specific ID, but only for QR3 to QR10.

data comb_new;
    set comb_new;
        array DQR(10) QR1-QR10;
            do i = 1 to 10;
                if id = "071800" then DQR(i) = 6;
                end;
            drop i;
run;

Second:

data comb_new;
    set comb_new;
        array p3t (8) QR3-QR10;
            do i = 1 to 8;
            if id = "141956" then p3t(i) = 6;
            end;
                if id = "461818" then p3t(i) = 6;
                end;
                if id = "261808" then p3t(i) = 6;
                end;
                if id = "261893" then p3t(i) = 6;
                end;
                if id = "261894" then p3t(i) = 6;
                end;
                if id = "011936" then p3t(i) = 6;
                end;
                if id = "141854" then p3t(i) = 6;
                end;
                if id = "061883" then p3t(i) = 6;
                end;
            drop i;
run;

Upvotes: 1

Views: 3560

Answers (1)

Gary Chung
Gary Chung

Reputation: 158

First change your array name from p3t to something without a number, like pat. SAS is more finicky about array names, and you may eliminate the error just by doing that.

Second, check your dataset comb_new after the conclusion of the first DATA step. An illegal reference will happen if any of the variables QR3-QR10 don't exist in your dataset.

Upvotes: 1

Related Questions