Updated March 6, 2023
Introduction to DO WHILE in SAS
SAS is a statistical analysis system that gives a complete solution for business analysis such as analyses, reporting, data mining, and predictive modeling with the help of powerful visualizations and interactive dashboards. It is mainly used for medical purpose analysis. For programming, it has the two steps data step and procedure step. In data, we have to explain the data we are giving and the procedure step it helps for the execution.
In SAS there are three basic loops that are DO LOOP, DO UNTIL and DO WHILE Here we are introducing DO WHILE LOOP. It is a control flow statement. In SAS statement repeatedly executes as per the condition until the while condition becomes false.
Syntax:
DO WHILE (condition); Statements;
;
END
In syntax, we have to give conditions inside the brackets. In the second line, we have to give the statements for the execution then we have to give END command for closing the loop.
Flow Chart:
In this flowchart clearly know that it stops the execution when the while condition becomes false For details please check below with the working and examples.
Working
All of you know that the DO WHILE LOOP helps for the repeat calculation at multiple numbers of times as per the condition. In SAS normally have to stop iteration when the certain is met. It has two options normally DO UNTIL and DO WHILE loop. In DO WHILE LOOP it stops iteration when the while condition fails. The condition must be checked in each iteration once it fails it stops the execution. In coding is very useful for repetition cases and sequence generation cases. Easily generate sequence as per the condition. For easy knowing while we taking the financial part of our life most of the people had loan or EMI. So, we have to calculate repayment such as how many times we have to repay it can easily calculate with DO WHILE loop. We need amount details only. Here we are explaining just simple program only.
Program #1
Data new; i=1;
do while(i<=5);output; i=i+1;
end;
proc print new; run;
Explanation:
In this program, we just give the name of the data as new. Here we are going to print up to 1 to 5. In the data step after naming the data we just take I as a variable and gave the value as 1 then the DO WHILE LOOP condition I <=5. After it iterates as per the given condition. It will generate up to 5 after that while loop fails Suddenly it stops the execution.
Output:
Program #2
data Work* investment do while(capital<50000); capital+capital *,10; year+1;
Output; End;
Proc print Work*investment Run;
Explanation:
In this program, I just give the work* investment. Because the program is to calculate the amount of capital as per year. Normally I just give a name as per the program because it is very useful to keep the file after that I give the condition on DO WHILE LOOP in that the capital less than 50000 after that give the statements for calculation and for the year and I give output statement and procedural steps. It will generate the capital by year until the while condition fails.
Output:
Conclusion
Normally all type of programming languages has the DO WHILE LOOP.SAS is a Business Analytical software also. In SAS very easy to write and run the program. Because lower case and upper case characters are allowed .it has two steps data step and procedure step. In DO WHILE LOOP iterates the statements as per the given condition until while condition becomes wrong. It has a very important role in our daily life. Because if you programmer it helped for the repetition of calculation and if you are the normal person it used to calculate some essential financial calculations such as EMI calculations how many months we have repay the amount like that. So, we think a very important portion it helps some logical calculations as per our needs.
Recommended Articles
This is a guide to DO WHILE in SAS. Here we discuss the Introduction, syntax, flow chart, How to work? with program. You may also have a look at the following articles to learn more –