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

My code is returning an error an am not sure why

 

Original code

 

DATA scoredata1;
set scoredata0;

Array sc(3) score1 score2 score3;
Array new (3) ns1 ns2 ns3;
DO i=1 TO 3;
IF sc(i)=777 then new(i)= .;
else if sc NE 777 then new(i) = sc(i) ;
end;
run;

 

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 DATA scoredata1;
74 set scoredata0;
75
76 Array sc(3) score1 score2 score3;
77 Array new(3) ns1 ns2 ns3;
78 DO i= 1 TO 3;
79 IF sc(i) = 777 then new(i)= .;
80 else if sc NE 777 then new(i) = sc(i);
ERROR: Illegal reference to the array sc.
81 end;
82 run;
 
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.SCOREDATA1 may be incomplete. When this step was stopped there were 0 observations and 9 variables.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.02 seconds
 
 
 
 
 
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
else  new(i) = sc(i) ; 

is all you need i think 

 

The error is you are mising the array index while referencing in your

 

else if sc NE 777 then new(i) = sc(i) ; 

which should have been

else if sc(i) NE 777 then new(i) = sc(i) ; 

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20
else  new(i) = sc(i) ; 

is all you need i think 

 

The error is you are mising the array index while referencing in your

 

else if sc NE 777 then new(i) = sc(i) ; 

which should have been

else if sc(i) NE 777 then new(i) = sc(i) ; 
rylife
Fluorite | Level 6

Thanks!

novinosrin
Tourmaline | Level 20

Or even terse would be just one statement and that is

if sc(i) NE 777 then new(i) = sc(i) ; 

 

Coz new(i) is anyway initialised with