Python and the SAS/IML language fall into this category. Some languages do not support a special switch statement, but instead require that you use IF-THEN/ELSE statements. Whereas the CASE-WHEN statement in SAS executes one statement, the switch-case statement implements fallthrough, so C-programmers often use the break The C/C++ and Java/Javascript languages support a switch-case statement. The SQL language supports a CASE-WHEN statement. Other languages have similar branching statements. SELECT-WHEN statement is not as flexible as the IF-THEN/ELSE statement, but, when applicable, it results in very clean and easy-to-read programs. I use the SELECT-WHEN statement as a "table lookup" when a program needs to branch according to the value of a single categorical variable that has three or more valid values. When ( 'Non-smoker' ) do /* execute multiple statements */ In the WHEN statement you can specify multiple values in a comma-separated list: For example, in a statistical analysis you might want to combine the 'Heavy' and 'Very Heavy' categories into a single group. You can also combine categories in a WHEN statement. Notice that you can use the OTHERWISE keyword to handle missing values, invalid data, or default actions. If the variable has that value, the program conditionally executes a statement, which in this example assigns a value to the Smoking_Cat variable. Each WHEN statement specifies a particular value for the variable. You then list a sequence of WHEN statements. You specify the name of a variable on the SELECT statement. The SELECT-WHEN statement is easy to read. When ( 'Very Heavy (> 25)' ) Smoking_Cat= 5 When ( 'Moderate (6-15)' ) Smoking_Cat= 3 * example of using the SELECT statement */ data Heart / view=Heart The following DATA step view implements a recoding scheme, which is sometimes the easiest way toįorce levels of a nominal variable to appear in a natural order during a SAS analysis. The Smoking_Status variable is a categorical variable that encodes the average number of cigarettes that each patient smokes per day. The following example uses the Sashelp.Heart data set, which containsĭata for 5,167 patients in a medical study. Usually the variable can have three or more valid values that you want to handle.
![base sas interview questions on data step and proc step base sas interview questions on data step and proc step](https://image.slidesharecdn.com/basesasinterviewquestions-130716042242-phpapp02-150603093127-lva1-app6891/95/base-sas-interview-questions-7-638.jpg)
(sometimes simply called the SELECT statement) enables you to conditionally execute statements based on the value of a single categorical variable. Sometimes a long sequence of IF-THEN/ELSE statements is necessary, such as when you are testing complex logical conditions.Īn alternative control statement in SAS is the SELECT-WHEN statement.
![base sas interview questions on data step and proc step base sas interview questions on data step and proc step](http://www.multisoftsystems.com/blog/wp-content/uploads/SAS_QA.png)
I have seen SAS programs that contain contains dozens of ELSE clauses. Of course, you can handle more cases by using multiple ELSE IF statements. The basic If-THEN statement handles two cases: if a condition is true, the program does one thing, otherwise the program does something else. Every beginning SAS programmer learns the simple IF-THEN/ELSE statement for conditional processing in the SAS DATA step.