data work.sets; do until (prod gt 6); prod + 1; end; run;
What is the value of the variable PROD in the output data set?
1. 6 2. 7 3. 8 4. . (missing numeric)
Correct Answer : 2 Because of prod + 1 statement, SAS compiler will assume a retain prod 0; statement. First loop => prod = 1 => (1 gt 6) => false, loop continues
Second loop => prod = 2 => (2 gt 6) => false, loop continues ..... last loop => prod = 7 => (7 gt 6) => true, do until loop exits and pdv writes prod value of 7 to output dataset.
Syntax DO UNTIL (expression); ...more SAS statements... END;
Arguments (expression) is any SAS expression, enclosed in parentheses. You must specify at least one expression. Details The expression is evaluated at the bottom of the loop after the statements in the DO loop have been executed. If the expression is true, the DO loop does not iterate again. Note: The DO loop always iterates at least once. There are three other forms of the DO statement: The DO statement, the simplest form of DO-group processing, designates a group of statements to be executed as a unit, usually as a part of IF-THEN/ELSE statements. The iterative DO statement executes statements between DO and END statements repetitively based on the value of an index variable. The DO WHILE statement executes statements in a DO loop repetitively while a condition is true, checking the condition before each iteration of the DO loop. The DO UNTIL statement evaluates the condition at the bottom of the loop; the DO WHILE statement evaluates the condition at the top of the loop. Note: The statements in a DO UNTIL loop always execute at least one time, whereas the statements in a DO WHILE loop do not iterate even once if the condition is false.
Question :The SAS data sets WORK.EMPLOYEE and WORK.SALARY are shown below: WORK.EMPLOYEE WORK.SALARY fname age name salary Bruce 30 Bruce 25000 Dan 40 Bruce 35000 Dan 25000 The following SAS program is submitted: data work.empdata; by fname; totsal + salary; run; Which one of the following statements completes the merge of the two data sets by the FNAME variable? 1. merge work.employee work.salary (fname = name); 2. merge work.employee work.salary (name = fname); 3. merge work.employee work.salary (rename = (fname = name)); 4. merge work.employee work.salary (rename = (name = fname));
Correct Answer : 4 Because the two data sets are merged by fname variable. You need to rename the name variable of the salary data set to fname. Correct way to rename is (rename = (name = fname)) (rename = (original_var_name= new_var_name)) The original var in this case is name and needs to be renamed fname. So 4 should be the correct answer. You merge data sets using the MERGE statement in a DATA step. The form of the MERGE statement that is used in this section is the following: MERGE SAS-data-set-list; BY variable-list; SAS-data-set-list is the names of two or more SAS data sets to merge. The list may contain any number of data sets. variable-list is one or more variables by which to merge the data sets. If you use a BY statement, then the data sets must be sorted by the same BY variables before you can merge them. Syntax RENAME=(old-name-1=new-name-1 (...old-name-n=new-name-n)) Syntax Description : old-name : the variable you want to rename. new-name : the new name of the variable. It must be a valid SAS name. If you use the RENAME= data set option when you create a data set, the new variable name is included in the output data set. If you use RENAME= on an input data set, the new name is used in DATA step programming statements. If you use RENAME= on an input data set that is used in a SAS procedure, SAS changes the name of the variable in that procedure. If you use RENAME= with WHERE processing such as a WHERE statement or a WHERE= data set option, the new name is applied before the data is processed. You must use the new name in the WHERE expression. If you use RENAME= in the same DATA step with either the DROP= or the KEEP= data set option, the DROP= and the KEEP= data set options are applied before RENAME=. You must use the old name in the DROP= and KEEP= data set options. You cannot drop and rename the same variable in the same statement. Note: The RENAME= data set option has an effect only on data sets that are opened in output mode
Question : The SAS data set PETS is sorted by the variables TYPE and BREED. The following SAS program is submitted: proc print data = pets; var type breed; sum number; run; What is the result?
1. The SUM statement produces only a grand total of NUMBER. 2. The SUM statement produces only subtotals of NUMBER for each value of TYPE. 3. The SUM statement produces both a grand total of NUMBER and subtotals of NUMBER for each value of TYPE. 4. Nothing is produced by the SUM statement; the program fails to execute.