DSCI 325 Midterm Practice Test Spring 2017 Name: 1. Consider the following four names used to create a SAS data set: work.test temp.test sasuser.test test How many of these will be stored as permanent data sets? a. None b. One c. Two d. Three 2. The SAS informat 4. indicates the variable should be stored as a. A monetary value having field width 4 b. A numeric value to 4 decimal places c. A numeric variable with width 4 d. A character value with width 4 3. Consider the code below. DATA Classes; INPUT Subject $ CourseNum $ Enrollment; DATALINES; STAT 325 9 MATH 100 37 STAT 21 41 ; PROC CONTENTS; In which SAS library will the output data set Classes be stored? a. The WORK library. b. The SASUSER library. c. The TEMP library. d. The data set will not be stored in any SAS library since no library was specified in the program. 4. Consider the following program. DATA test; INFILE 'Desktop/test.dat'; INPUT var1 var2 +3 var3; What does the +3 do? 1
a. It moves the pointer down to the third row of the data file (i.e., to the third observation in the data set). b. It moves the column pointer to column 3. c. It adds 3 to the value read into var2. d. It advances the column pointer 3 places. Questions 5-6 refer to the following data sets, Work.One and Work.Two. Work.One Work.Two 5. Suppose the following programming statements are submitted (note that both data sets are already sorted by Id). DATA Work.Both; MERGE Work.One Work.Two; BY Id; Which of the following is the correct data set Work.Both? a. c. b. d. 2
6. Suppose the following programming statements are submitted. DATA Work.Both; SET Work.One Work.Two; Which of the following is the correct data set Work.Both? a. c. b. d. 7. The NationalParks data set contains four variables: Park_Name, Region, Museums, and Camping. Suppose the following SAS program is submitted. PROC MEANS DATA = Hooks.NationalParks MEAN; <insert statement(s) here> The following report is produced: Which of the following contains the missing statement(s) needed to produce this report? a. CLASS Region; b. VAR Museums Camping; c. CLASS Region; VAR Museums Camping; d. VAR Region; CLASS Museums Camping; 3
8. The following SAS program is submitted: DATA WORK.TEMP; Char1='0123456789'; Char2=SUBSTR(Char1,3,4); What is the value of Char2? a. 23 b. 34 c. 345 d. 2345 9. The following SAS program is submitted: DATA WORK.TEMP; Char1='0123456789'; Char2=FIND(Char1,'3', 5); What is the value of Char2? a. 0 b. 4 c. 6 d. 34567 e. 23456 10. Suppose the following statements were submitted to SAS. %MACRO PrintData(Dataset = ); PROC PRINT DATA = &Dataset; %MEND PrintData; %PrintData(Dataset = Hooks.Grades); Which of the following statements is most correct? a. This code will not produce any output because a %LET statement was never used to define the value of the macro variable Dataset. b. This code will not produce any output because the last statement should have been written as follows to correctly invoke the macro: %PrintData(Dataset = &Hooks.Grades); c. This code will print the data set named Hooks.Grades. d. This code will print the data set named Dataset. 4
11. Consider the following code which is used to merge two data sets named A and B. Write the appropriate IF statement to create the desired data set containing only the matches (i.e., the observations that were in both of the original data sets). DATA AB; MERGE A(in=InA) B(in=InB); BY ID; 12. Consider the following program. DATA Work.Salary; INPUT Name $ MStatus $ Salary $ ; DATALINES; Mary S 45600 Scott M 46200 Tanya M 52150 Tim M 48400 ; PROC PRINT DATA=Salary; WHERE Salary > 50000; When this code was submitted, no output was produced. The Log window displayed the following. 5
a. Explain why the Work.Salary dataset was not successfully created in SAS. b. Rewrite the INPUT statement so that the data set is successfully created. INPUT 6
13. Consider the following code which is used to calculate summary statistics for only the year specified with a macro variable. Finish the WHERE statement to produce the desired output for any given year specified by the user in the %LET statement. %LET Year = 2014; PROC MEANS DATA = MN_precip N Q1 MEDIAN Q3 MEAN STD; VAR precip; WHERE 14. Now, suppose a title statement is added to the above code as follows. %LET Year = 2014; TITLE 'Year = &Year'; PROC MEANS DATA=precip2 N Q1 MEDIAN Q3 MEAN STD; VAR precip; When the program is resubmitted, the following output is obtained. Note that your title is incorrect: it should specify that the output is relevant to the year 2014. Fix the TITLE statement so that the correct title is displayed for any given year specified by the user in the %LET statement. TITLE 7
15. Suppose the director of sales wants a report generated for all employees that report directly to him. The data for all employees in the company is contained in the file HR.EmployeeInfo. There is a variable in this data set named Department that takes on the value Sales for all employees that report to this director of sales. Finish both the SELECT clause and the FROM clause below to query all variables in this file for only the employees that report to this director. (4 pts) PROC SQL; SELECT FROM QUIT; 16. Consider the previous problem. This time, suppose the director has requested that the report contain information on only the following variables from the HR.EmployeeInfo data set: Employee_ID, Job_Title, and Salary. Furthermore, he wants the variables Employee_ID and Job_Title to be labeled Employee ID and Job Title in the final report (i.e., he doesn t want the underscores to appear). He still wants the report to contain information on only employees that report to him. Modify your PROC SQL statements from above to obtain the query the director has requested. (5 pts) PROC SQL; SELECT FROM QUIT; 8
17. Once again, consider the scenario presented in problem 9. This time, suppose the director has requested that you calculate the Number of employees in the Sales Department and the Average Salary of the employees in the Sales Department. These columns should be labeled Count and Average Salary in the report you prepare. Write PROC SQL statements to obtain the output the director has requested. (5 pts) PROC SQL; SELECT FROM QUIT; 9