DSCI 325 Practice Midterm Questions Spring 2016 1. In SAS, a statement must end a. with a colon b. with a semicolon c. in a new line d. with the command RUN 2. Which of the following is a valid variable name in SAS? a. Var.5 b. 5var c. Var_5 d. Var/5 3. Which of the following is not true about the work library in SAS? a. It is the default library where a data set is stored if no other library is specified. b. It is a library that comes pre-installed with SAS. c. It is equivalent to the sasuser library. d. Data sets in the work library are removed from this library upon exiting a SAS session. 4. Suppose you have the following data lines. Ronald Reagan 01-20-198101-21-1985Republican George Bush 01-20-1989 Republican William J. Clinton01-20-199301-20-1997Democratic George W. Bush 01-20-200101-20-2005Republican Barack Obama 01-20-200901-21-2013Democratic Which INPUT statement is the best for reading in the data? a. INPUT Name $ FirstInaugDate $ SecondInaugDate $ Party $; b. INPUT Name $ 1-18 FirstInaugDate $ 19-28 SecondInaugDate $ 29-38 Part $ 39-48; c. INPUT Name $ 1-18 FirstInaugDate MMDDYY10. SecondInaugDate MMDDYY10. Party $ 39-48; d. INPUT Name :$18. FirstInaugDate :$10. SecondInaugDate :$10. Party $ 39-48; 5. Which of the following SAS functions works on character variables? a. MEAN b. SUM c. LENGTH 1
6. The SAS informat $16. indicates a. A date in the year 2016 b. A monetary value having field width 16 c. A numeric value to 16 decimal places d. A character variable with width 16 7. In SAS, newly created variables based on variables already in a data file a. must be named in the INPUT statement. b. must be created with other numeric variables only (i.e., not with other character variables). c. are not printed out when the resulting data set is printed. d. can be created within the DATA step. 8. 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 9. Suppose the following program is run in SAS. DATA fruits; INPUT fruit1 $ fruit2 $; Apple kiwi grape orange mango lemon pear banana PROC PRINT; Which of the following is the resulting output? a. c. b. d. 2
10. Suppose the following program is run in SAS (note the use of @@ in the INPUT statement). DATA fruits; INPUT fruit1 $ fruit2 $ @@; Apple kiwi grape orange mango lemon pear banana PROC PRINT; Which of the following is the resulting output? a. c. b. d. 11. Suppose the following program is run in SAS. DATA test; INPUT Name $ var1 var2; IF (var1 LT 5 OR var1 GE 10) THEN var3 = var1 + var2; ELSE var3 = var1 - var2; Jim 4 6 Sam 7 10 Angie 12 8 ; PROC PRINT; Sketch in the results in the table below that would appear in the Results Viewer window. 3
12. Consider the following SAS Program which reads in Vehicle Identification Numbers (VINs) and creates two new variables, Make and Features, based on the VIN. DATA VehicleIDs; INPUT VIN $; Make = SUBSTR(VIN, 2, 1); Features = SUBSTR(VIN, 4, 5); 1F1JF27W86J178227 4S4BP67C454326624 ; PROC PRINT; a. Sketch in the results in the table below that would appear in the Results Viewer window b. The model year of a vehicle is contained in the 10 th position of the VIN. Write a statement that creates a new variable named ModelYear that pulls off the 10 th position from the VIN. ModelYear = c. The features of a vehicle are described in the last six digits of the VIN. Write a statement that creates a new variable named Features that pulls off the last six digits from the VIN. Features = 4
13. Suppose the following program is submitted to read in a data set containing students scores. DATA Grades; INPUT Student HW1 HW2 HW3 Quiz1 Quiz2 Quiz3 Midterm Final; Tim 9 10 9 4 3 3 32 30 Sarah 8 7 6 3 4 4 30 32 John 9 8 8 4 4 3 37 32 Kara 10 10 10 5 4 5 38 39 ; PROC PRINT; When this code was submitted, the following output was produced. The Log window displayed the following: a. Explain why the Grades data set was not successfully created in SAS. (2 pts) b. Complete the INPUT statement below to successfully read in the data. (2 pts) INPUT 5
14. Consider the Grades data set from the previous problem. Suppose that an instructor wanted to write a SAS program that would assign grades as follows: 90% and above is an A, 80% and above (but less than 90%) is a B, 70% and above (but less than 80%) is a C, etc. The instructor wrote the following program to do this. DATA Grades; INPUT Student $ HW1 HW2 HW3 Quiz1 Quiz2 Quiz3 Midterm Final; PointsEarned = HW1 + HW2 + HW3 + Quiz1 + Quiz2 + Quiz3 + Midterm + Final; Percent = PointsEarned / 125 ; IF Percent GE.90 then Grade = 'A'; IF (Percent GE.80 AND Percent LT.90) then Grade = 'B'; IF (Percent GE.70 AND Percent LT.80) then Grade = 'C'; IF (Percent GE.60 AND Percent LT.70) then Grade = 'D'; ELSE Grade = 'F'; Tim 9 10 9 4 3 3 32 30 Sarah 8 7 6 3 4 4 30 32 John 9 8 8 4 4 3 37 32 Kara 10 10 10 5 4 5 38 39 ; PROC PRINT; The instructor was surprised to see the results, which are given below (there were no errors in the Log window). Rewrite the middle portion of the code in the box below to produce the desired outcome. (3 pts) DATA Grades; INPUT Student $ HW1 HW2 HW3 Quiz1 Quiz2 Quiz3 Midterm Final; PointsEarned = HW1 + HW2 + HW3 + Quiz1 + Quiz2 + Quiz3 + Midterm + Final; Percent = PointsEarned / 125 ; 6
15. Data from the file people.txt was used to create a SAS data set named people. The file and SAS code are shown below. DATA people; INFILE 'D:\Desktop\people.txt'; INPUT Name $ Age Gender $; In the same session of SAS and after submitting the above program (so the SAS data set named people exists in the work library), you decide to create a permanent data set named people2 to be stored in the sasuser library. You use the following code. DATA sasuser.people2; SET work.people; INPUT Name $ Age Gender $; The program fails to run, and SAS returns the following in the log window. Rewrite the code (in the box on the right) to successfully create the people2 data set to be stored in the sasuser library. (3 pts) Original Code: New Code: DATA sasuser.people2; SET work.people; INPUT Name $ Age Gender $; 7
16. Which statement is correct concerning the merging of data sets? a. The MERGE statement must refer to permanent data sets. b. The variables in the BY statement can be in only one of the data sets. c. Only two data sets can be specified in the MERGE statement. d. When you use the MERGE statement with the BY statement, the data must be sorted or indexed on the BY variable. 17. The following SAS log was created after running a program to merge two data sets. Note that the first data set contains 77 observations and the second contains 148 observations. Explain why the final merged data set contains more observations than either of the original data sets. 18. Consider the following code which is used to merge two data sets named products and costs. Write the appropriate IF statement to create the desired data set containing only nonmatches. DATA products_costs; MERGE products(in=inprod) costs(in=incost); by ID; 19. Two SAS data sets need to be merged, but the BY variables have different names. What can be done to enable the data sets to be merged? 8
20. Explain the difference between appending, concatenating, and merging data sets. 21. Consider the original data set named Emps. Suppose you run a program to append the three data sets Emps2008, Emps2009, and Emps2010 to this original file. a. How many observations will be in Emps after appending the three data sets? b. How many variables will be in Emps after appending the three data sets? 22. Consider the original data sets named EmpsCN and EmpsJP. Suppose you run a program to concatenate these data sets to create a new file named EmpsA112. How many variables will be in EmpsA112? Program to concatenate: 9
23. Which method would you use if you wanted to create a new variable at the time of concatenation? a. APPEND procedure b. SET statement 24. Which DATA step correctly references the macro variable SYSDATE? a. title "February Trials as of &sysdate"; data drg.febtrial; set drg.trial; if month=2 and year=2013; b. title 'February Trials as of sysdate'; data drg.febtrial; set drg.trial; if month=2 and year=2013; 25. Which of the following statements creates a macro variable named site with a value of 75? a. let site='75'; b. &let site=75; c. %let site=75; d. %let site='75'; 26. Write a statement below that creates a macro variable named rate that has a value of satisfactory. 27. The following %LET statement creates the macro variable name with a value of prod. %let name=prod; Write a DATA statement that combines a macro variable reference to name with a prefix to create the SAS data set Reg.Newprod. 10
28. Which DATA step below correctly references the macro variable site? The value of site is used to create the data set name Westprod as well as to select observations for which the value of region is west. a. %let site=west; data &site.prod; set reg.productn; if region='&site'; b. %let site=west; data &site.prod; set reg.productn; if region="&site"; c. %let site=west; data &siteprod; set reg.productn; if region='&site'; 11