Loop in sas

similar to other languages where we use different types of looping statements such as for loop for each while . We have three types of looping statement in sas. and all of them start with do prefix.

Do

DIFFERENCE BETWEEN THESE loop

statement to identify when to stop the execution.

a) do iterative

Fixed number of loops

Loop 1.1do j=1 to 10 by 1;
year+1;
cost=1.015*cost;
output;
end;

b) Do conditional loops

there are two condition to state the stopping value using do while and do until.

do until checks condition at the bottom whereas do while checks the condition at the top of loop

Loop 1.2do until(North_Carolina gt South_Carolina);
year+1;
North_Carolina=1.02*North_Carolina;
South_Carolina=1.01*South_Carolina;
output;
end;
Loop 1.3do while(North_Carolina le South_Carolina); 
year+1;
North_Carolina=1.02*North_Carolina;
South_Carolina=1.01*South_Carolina;
output;
end;

C) do iterative-conditional

There may be the cases where the data may be infinite loops as a result there will be loss of huge amount of computational power. In order to remove this burden we can make use of iterative conditional type of loop where both the iterative loop is defined along with the condition to stop by.

Loop 1.3do j=1 to 15 until(North_Carolina gt South_Carolina); 
year+1;
North_Carolina=1.016*North_Carolina;
South_Carolina=1.012*South_Carolina;
output;
end;

thank you for reading. may this help you to understand.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store