Question

I want to have a if condition within a loop. That is As long as id < 10, check if Modc_initial is equal to MODC, if true then set d = 12

This is the code I tried bit not working, can anyone please help.

LOOP if (id LT 10)

IF(Modc_initial EQ MODC))

COMPUTE d = 12.

END LOOP.

EXECUTE.

Was it helpful?

Solution

You can either use a one line conditional of the form IF (condition) d = 12. or a multiple line DO IF. Below I provide an example of DO IF adapted to your syntax.

data list free / id MODC Modc_initial.
begin data
1 3 3
2 3 5
12 1 1
end data.

LOOP if (id LT 10).
DO IF (Modc_initial EQ MODC).
  COMPUTE d = 12.
END IF.
END LOOP IF (d = 12).
EXECUTE.

Note you had a period missing in your original syntax on the initial LOOP. I also added an end loop condition, otherwise the code as written would just go until the maximum set number of loops per your system.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top