I have just started using macros and arrays in SAS and am a beginner user of SAS. I need your guidance and advice on the most effective way to increment score values which are less than 65. I have a dataset of 10 observations on their student IDs and their test scores. I have the following code to increment the test scores values which are less than 65. Is there another way I can increment test score values which are less than 65 to just above 65 so that it stops if the value is 65 or greater.
data scores;
set scores;
array Test{i} Test_1-Test_5;
Test{i} = 1;
do i=1 to 5;
do until(Test{i}>65);
Test{i} = Test{i}+0.1;
end;
I am getting an error with this code:
Mixing of implicit and explicit array subscripting not allowed
There was 1 unclosed DO unblock
Please let me know if there is anything wrong in this code. Thank you for your time.
A few problems that have been corrected with the below code:
Your declared array uses the variable i
as the dimension. i
is not assigned a value until the outer do
loop. Use the wildcard *
instead. This will tell SAS to automatically generate the dimension depending on the number of variables specified in the array.
Test[i]
is given a value, but i
has not yet been assigned. Place test[i]
within your outer do
loop
You are missing an end
statement for the outer do
loop.
Code:
data test;
array Test[*] Test_1-Test_5;
do i=1 to 5;
Test[i] = 1;
do until(Test[i]>65);
Test[i] = Test[i]+0.1;
end;
end;
run;