Question : A SAS PRINT procedure output of the WORK.LEVELS data set is listed below: Obs name level 1 Frank 1 2 Joan 2 3 Sui 2 4 Jose 3 5 Burt 4 6 Kelly . 7 Juan 1 The following SAS program is submitted: data work.expertise; set work.levels; if level = . then expertise = 'Unknown'; else if level = 1 then expertise = 'Low'; else if level = 2 or 3 then expertise = 'Medium'; else expertise = 'High'; run; Which of the following values does the variable EXPERTISE contain? 1. Low, Medium, and High only 2. Low, Medium, and Unknown only 3. Low, Medium, High, and Unknown only 4. Low, Medium, High, Unknown, and ' ' (missing character value)
Correct Answer : 2
Explanation: IF expression THEN statement; ELSE statement; Arguments
expression is any SAS expression and is a required argument. statement can be any executable SAS statement or DO group. SAS evaluates the expression in an IF-THEN statement to produce a result that is either non-zero, zero, or missing. A non-zero and nonmissing result causes the expression to be true; a result of zero or missing causes the expression to be false. If the conditions that are specified in the IF clause are met, the IF-THEN statement executes a SAS statement for observations that are read from a SAS data set, for records in an external file, or for computed values. An optional ELSE statement gives an alternative action if the THEN clause is not executed. The ELSE statement, if used, must immediately follow the IF-THEN statement. Using IF-THEN statements without the ELSE statement causes SAS to evaluate all IF-THEN statements. Using IF-THEN statements with the ELSE statement causes SAS to execute IF-THEN statements until it encounters the first true statement. Subsequent IF-THEN statements are not evaluated. Note: For greater efficiency, construct your IF-THEN/ELSE statement with conditions of decreasing probability.
Question : The contents of the raw data file EMPLOYEE are listed below:
--------10-------20-------30 Ruth 39 11 Jose 32 22 Sue 30 33 John 40 44 The following SAS program is submitted: data test; infile 'employee'; input employee_name $ 1-4; if employee_name = 'Ruth' then input idnum 10-11; else input age 7-8; run; Which one of the following values does the variable IDNUM contain when the name of the employee is "Ruth"? 1. 11 2. 22 3. 32 4. . (missing numeric value)
Correct Answer : 2
Exp: This is a free listing format and the cursor moves to the second record and picks up 22. if you run the program as it is the answer should be and is '2' but if you change the position of idnum to 9-10, then the answer is 22. As the pointer moves to next column when its checks the condition.... The output would be
employee_name idnum age Ruth 22 . Sue . 0(the zero value is of John age 40)
Question : The contents of the raw data file EMPLOYEE are listed below:
--------10-------20-------30 Ruth 39 11 Jose 32 22 Sue 30 33 John 40 44 The following SAS program is submitted: data test; infile 'employee'; input employee_name $ 1-4; if employee_name = 'Sue' then input age 7-8; else input idnum 10-11; run; Which one of the following values does the variable AGE contain when the name of the employee is "Sue"?
1. 30 2. 33 3. 40 4. . (missing numeric value)
Correct Answer : 4 Answer should be 4(missing); question talks about when the conditon is "sue" and not the program output To get the correct result data test; infile employee; input employee_name $ 1-4 @; if employee_name = 'Sue' then input age 6-7; else input idnum 8-10; run; proc print; run;