Programming 2

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Correct Answer: True The subsetting IF should be placed in the DATA step as soon as all variables that are needed to evaluate the condition in the IF statement are assigned values.

10.Generally, the most efficient place to put a subsettingIF statement is as early as possible in the DATA step. a. True b. False

Correct Answer: c

8.What does a forward slash (/) indicate when used in an INPUT statement? a. Load the next file in the input buffer. b. Load the next field in the input buffer. c. Load the next record in the input buffer. d. none of the above

Correct Answer: a The SCAN function is used to extract words from a character when you know the order of the words, when their position varies, and when the words are marked by some delimiter. In this case, you don't need to specify delimiters, because the blank and the comma are default delimiters.

1.The variable Address2 contains values such as Piscataway, NJ. Select the statement that extracts and assigns the two-letter state abbreviation to a new variable named State. a. State=scan(Address2,2); b. State=scan(Address2,13,2); c. State=substr(Address2,2); d. State=substr(Address2,13,2);

Correct Answer: True

1.When a logic error occurs, SAS displays unexpected results. A. True B. False

Correct Answer: b The sum statement creates the variable on the left of the plus operator and retains the value of the variable in the PDV across iterations of the DATA step.

1.Which statement retains the value of Sales2Dte in the PDV across iterations of the DATA step? a. retain Sales2Dte=10; b. Sales2Dte+Total_Retail_Price; c. Sales2Dte=Sales2Dte+Total_Retail_Price;

Correct Answer: c

1.Which style of INPUT statement specification is used to read data in fixed columns? a. column input b. formatted input c. a and b d. none of the above

Correct Answer: True ThesubsettingIF should be placed in the DATA step as soon as all variables that are needed to evaluate the condition in the IF statement are assigned values.

10.Generally, the most efficient place to put a subsettingIF statement is as early as possible in the DATA step. A. True B. False

Correct Answer: c The INPUT function explicitly convert character values to numeric values. You specify the keyword INPUT followed by the variable name and then the informat. The variable name and informatare enclosed in parentheses and separated by a comma. A numeric informatis needed for character-to-numeric conversions.

10.Which of the following functions converts the character values of Base to numeric values? a. put(comma10.2,Base) b. put(Base,comma10.2) c. input(Base,comma10.2) d. input(comma10.2, Base)

Correct Answer: d The RETAIN statement sets an initial value of 100to Count. The sum statementincrements Count by the value of Tens. The sum statement ignores the missing value in the third observation, and the resulting value of Count is 130.

2.Consider the program and data below. What is the value of Count after the third observation is read? a. missing b. 0 c. 100 d. 130

Correct Answer: d

2.In the INPUT statement, what is the syntax used to move the input pointer to a specified column? a. /n b. +n c. #n d. @n

Correct Answer: True

2.Logic errors are often more difficult to detect than syntax errors. a. True b. False

Correct Answer: c For every observation read, there are three observations created (25*3=75). The variableZone is added to the existing three variables to create fourvariables in total.

2.The data set shippingcontains 25 observations and three variables (Product, BoxSize,and Rate). How many observations and variables does the data set shippingzones have? a.25 observations, 4 variables b.75 observations, 3 variables c.75 observations, 4 variables

Correct Answer: d The SUBSTR function is best used when you know the exact position of the substring to extract from the character value. You specify the variable, the starting position, and the number of characters to extract.

2.The variable IDCode contains values such as 123FA and 321MB. The fourth character identifies gender. Select the statement that assigns this character code to a new variable named Gender. a. Gender=scan(IDCode,4); b. Gender=scan(IDCode,4,1); c. Gender=substr(IDCode,4); d. Gender=substr(IDCode,4,1);

Correct Answer: d The SUBSTR function is best used when you know the exact position of the substring to extract from the character value. You specify the variable, the starting position, and the number of characters to extract.

2.The variable IDCode contains values such as 123FAand 321MB. The fourth character identifies gender. Select the statement that assigns this character code to a new variable named Gender. a.Gender=scan(IDCode,4); b.Gender=scan(IDCode,4,1); c.Gender=substr(IDCode,4); d.Gender=substr(IDCode,4,1); ● ●

Correct Answer: b When the SUBSTR function is used on the left side on an assignment statement, it replaces characters at a specified position.

3.Due to growth within the 919 area code, the telephone exchange 555 is being reassigned to the 920 area code. The data set clients.piedmontincludes the variable Phone, which contains the telephone number in the form 808-555-1234. Which of the following programs correctly changes the values of Phone? a. data work.piedmont(drop=areacodeexchange); set clients.piedmont; Areacode=substr(phone,1,3); Exchange=substr(phone,5,3); if areacode='919' and exchange='555' then phone=substr('920',1,3); run; b. data work.piedmont(drop=areacodeexchange); set clients.piedmont; Areacode=substr(phone,1,3); Exchange=substr(phone,5,3); if areacode='919' and exchange='555' then substr(phone,1,3)='920'; run;

Correct Answer: b Three variables are read from the input data set, one of them (Month) is dropped when writing to the new data set.

3.If you submit the following program, which variables appear in the new data set? a. Month, Sport, Coach b. Sport, Coach c. none

Correct Answer: d The sum statement adds the result of the expression that is on the right side of the plus sign to the numeric variable that is on the left side. The new value is then retained for subsequent observations. The sum statement ignores the missing value, so the value of Count in the fourth observation is10+20+40, or 70.

3.Now consider the program below. What is the value of Count after the fourth observation is read? a. missing b. 0 c. 30 d. 70

Correct Answer: True For example, $8. indicates the field being read by the informathas a width of 8 characters.

3.The width of the input field can be specified by an informatwhen used with formatted input. A. True B. False

Correct Answer: False

3.When a logic error occurs, SAS writes an error message to the log. a. True b. False

Correct Answer: a Free-format data is dependent upon delimiters to separate the fields which may not be in fixed fields.

4.Formatted input cannot be used to read which of the following types of raw data? a. standard free-format data b. standard data in fixed fields c. nonstandard data in fixed field

Correct Answer: Yes You have to sort by the input group before you can use the DATA step to summarize. When you use a BY statement, the DATA step expects an input data set that is sorted by the order of the BY variables or one that has an appropriate index. If your input data set does not meet these criteria, then an error occurs. Either sort it with the SORT procedure or create an appropriate index on the BY variables.

4.Is the following statement true? To create an accumulating total for a group, you first have to sort the data by the grouping variable(s). A. Yes B. No

Correct Answer: False

4.Logic errors occur when program statements do not conform to the rules of the SAS language. a. True b. False

Correct Answer: b You cannot use a drop statement in a PROC Print statement.

4.Which program contains an error? data stresstest(drop=timemintimesec); set physical; TotalTime=(Timemin*60)+Timesec; run; procprint data=stressdata; labelTotalTime='Duration of Test'; drop TimeMin; run; procprint data=stresstest(keep=TotalTimeTimeMin); labelTotalTime='Duration of Test'; formatTimeMin5.2; run;

CorrectAnswer: b You must set the accumulating variable to zero at the start of each BY group so the summarized value will not consist of the accumulated total from the previous BY-group.

8. When using the DATA step to summarize grouped data, what is the first step in the process? a.Output the first observation of each BY group b.Set the accumulating variable to zero at the start of each BY group c.Increment the accumulating variable with a sum statement (automatically retains)

Correct Answer: b When you use the I modifier in the FIND function to make the search case-insensitive, you must enclose it in quotation marks.

4.Within the data set furn.bookcase, the variable Finish contains values such as ash, cherry, teak, and matte-black. Which of the following creates a subset of the data in which the values of Finish contain the string walnut? Make the search for the string case-insensitive. a. data work.bookcase; set furn.bookcase; if find(finish,'walnut',I); run; b. data work.bookcase; set furn.bookcase; if find(finish,'walnut','I')>0; run;

Correct Answer: b When you specify multiple BY variables, the primary BY variable (Gender) determines changes in the secondary BY variable (JobCode). Remember that neither FIRST. nor LAST. variables are stored in the new data set.

5. Which statement is true about the following program? a.A change in the value of LAST.JobCode causes the value of LAST.Gender to change. b.A change in the value of LAST.Gender causes the value of LAST.JobCode to be set to 1. c.Both LAST.JobCode and LAST.Gende rare stored in the new data set.

Correct Answer: d The first observation processed is 150, and the last observation processed is 200.

5.There are 300 observations in the trialsdata set. How many observations does the test data set contain? a.200 b.201 c.50 d.51

Correct Answer: c When functions are nested, the innermost function executes first and passes its result to an outer function. The LENGTH function returns the length of the string (13) to the SUBSTR function. The SUBSTR function extracts a 9-character string (13-4) starting from position 1.

5.What is the new value of Code? a. 96701-006 b. HNL: c. HNL:96701 d. 1-006

Correct Answer: c

5.Which of the following is not a task of the PUTLOG statement? a. Write text to the log. b. Write formatted values to the log. c. Write all the logic errors to the log. d. Write the values of all the variables to the log.

Correct Answer: c Remember that when you use formatted input, the column pointer control moves to the first column following the field that was just read.

5.Which set of instructions does not correctly read the values for Quantity(in the third field) after the values for Item(in the first field)? a. input Item $9. @20 Quantity 3.; b. input Item $9. +10 Quantity 3.; c. input Item $9. +11 Quantity 3.;

Correct Answer: c The value of the width must be wide enough to display the value of the variable as well as the quotation marks.

6.The variable Titleis 22 characters long. One of the values for Titleis My House on the Lane. Which of the following statements would provide the full value of the variable in the log if the data included two leading spaces? a. putlog Title $quote20.; b. putlog Title $quote22.; c. putlog Title $quote30.;

Correct Answer: d You can use a numbered range list to specify the variables Var1 through Var4. When you use a variable list, you must precede the list with the keyword OF. If you omit the OF, SAS will not interpret the arguments correctly.

6.Which function calculates the average of the variables Var1, Var2, Var3, and Var4? a. mean(Var1,Var4) b. mean(Var1-Var4) c. mean(of Var1,Var4) d. mean(of Var1-Var4)

Correct Answer: c Ordertimemust be read from the july.ordersfile to be eligible for dropping.

6.Which of the following programs correctly reads the july.orders data set? a.data fastorder(drop=Ordertime); set july.orders(keep=Product Units Price); if Ordertime<4; Total=Units*Price; run; b.data orders(drop=Ordertime); set july.fastorder(keep=Product Units Price); if Ordertime<4; Total=Units*Price; run; c.data fastorder(drop=Ordertime); set july.orders(keep=Product Units Price Ordertime); if Ordertime<4; Total=Units*Price; run;

Correct Answer: c You can use the @n column pointer control to read the values for Lnameand Fname. You can use either the / or #n line pointer control to advance the input pointer to the second and third lines of the raw data file to read the values for Department and Salary.

6.Which one of the following INPUT statements correctly reads the values for Fname(in the second field), Lname, Department, and Salary(in that order)? a. input @14 Fname$10. @1 Lname$10./ Department $7./ Salary comma10.; b. input @14 Fname$10. @1 Lname$10. #2 Department $7. #3 Salary comma10.; c. both a and b

CorrectAnswer: c If an observation in a BY group consists ofa single observation, then the observation is the first and last observation in the BY group. Therefore, the First.BY variable has a value of 1.The value of Last.BY-variable is also 1 because it is the also the last observation in a BY group.

7. If you process a BY group that consists of a single observation, what are the correct values of First.BY-variable and Last.BY-variable? a. First.BY-variable=0 Last.BY-variable=0 b. First.BY-variable=1 Last.BY-variable=0 c. First.BY-variable=1 Last.BY-variable=1 d. First.BY-variable=0 Last.BY-variable=1

Correct Answer: False The END= option does not control whether or not the last observation is executed.

7.The END= option in the SET or INFILE statement indicates that SAS should process the last observation. a. True b. False

Correct Answer: c The single trailing @ releases a record when a null INPUT statement executes, an INPUT statement without a trailing @ executes, or when the next iteration of the DATA step begins

7.The single trailing @ releases a record when which of the following conditions occurs? a. An INPUT statement without a trailing @ executes. b. The next iteration of the DATA step begins. c. both a and b

Correct Answer: c The FLOOR function returns the greatest integer less than or equal to the argument.

7.Which function returns the greatest integer less than or equal to the argument? a. CEIL b. INT c. FLOOR

Correct Answer: c The SELECT expression must be enclosed in parentheses, and SAS cannot evaluate the expression region=2,3,5.

7.Which of the following correctly writes observations to the tropicaldata set based on values of Region? a. select region; when (2,3,5) output tropical; otherwise; end; b. select; when (region=2,3,5) output tropical; otherwise; end; c. select (region); when (2,3,5) output tropical; otherwise; end;

Correct Answer: True

8. The END= option in the SET or INFILE statement creates a variable that acts as an end-of-file indicator. a. True b. False

Correct Answer: b An OUTPUT statement writes the current observation to every data set being created unless an explicit data set reference is made.

8.What happens when you submit the following code? a. Because the OUTPUT statement does not specify a data set, both output data sets are empty. b. All observations in the floradata set are written to both output data sets. c. The DATA step writes the first observation to each output data set and then stops processing because no RETURN statement is specified.

Correct Answer: a The PUT function explicitly converts numeric values to character values. You specify the keyword PUT followed by the variable name and then the format. The variable name and format are enclosed in parentheses and separated by a comma.

8.Which of the following functions can convert the values of the numeric variable Levelto character values? a. put(Level,3.) b. input(3.,Level) c. put(3.,Level) d. input(Level,3.)

Correct Answer: b When SAS usesthis subsetting IF statement, it checks to see if the value of LAST.JobTypeequals 1. If LAST.JobTypeequals 1, it means that it's the last observation in the BY group, and SAS will continue processing.

9. Which DATA step statement indicates to continue processing the last observation of a BY group? a. if first.jobtype; b. if last.jobtype; c. if first.jobtypethen output; d. if last.jobtypethen output=1;

Correct Answer: d When you use the PUT function, you must specify a format that can read the form of the values. The numeric format 4.1 correctly reads the values of SiteNum.

9.A typical value for the numeric variable SiteNum is 12.3. Which statement correctly converts the values of SiteNum to character values when creating the variable Location? a. Location=Dept||'/'||put(SiteNum, $3); b. Location=Dept||'/'||put(SiteNum,4); c. Location=Dept||'/'||put(SiteNum,3.1); d. Location=Dept||'/'||put(SiteNum,4.1);

Correct Answer: False The trailing @ specifies to hold the raw data record in the input buffer until SAS executes an INPUT statement with no trailing @ or the next iteration of the DATA step begins.

9.The trailing @ specifies to hold the raw data record in the input buffer until SAS executes a SET statement with no trailing @ or the next iteration of the DATA step begins. A. True B. False

Correct Answer: No For the first step, the missing value observation is not output at all. For the second step, the missing value observation is output to every data set listed in the DATA statement.

If the value of Region is missing (.), do these two DATA steps produce the same output? A. Yes B. No

Correct Answer: a

When you submit the following program, what is listed in the log? a. books, last of books, and the values for all the variables in the last observation b. books, last of books, and the values for all the variables in all observations c. the values of all the variables for the last observation

Correct Answer: d BY-group processing requires that the data set listed in the SET statement is sorted by the BY variable(s). BY-group processing creates a FIRST. and LAST.variable for each variable in the BY statement, and identifies the first and last observation in each BY group. SAS assigns a value of 1 to the FIRST. and LAST. variables with the first occurrence of a new value for those variables; otherwise, they're assigned a value of 0.

Which statement is false about BY-group processing when you use the BY statement with the SET statement? a.The data sets listed in the SET statement must be indexed or sorted by the values of the BY variable(s). b.The DATA step automatically creates two new variables, First. and Last. ,for each variable in the BY statement. c.The First. and Last. variables identify the first and last observation in each BY group, respectively. d.The First. and Last. variables have values of 0when SAS is processing an observation with the first occurrence of a new value for those variables, and a value of 1for the other observations.


Kaugnay na mga set ng pag-aaral

Ch 7 - Individual and Group Decision Making learnsmart/smartbook

View Set

American Govt (PLS) Chapter 4 Smartbook

View Set

Palabras que terminan en -tad/-dad - Femeninas

View Set

Anxiolytic and Hypnotic Agents; Chapter 20

View Set

Civil Rights and Society: Minersville School Board v. Gobitis (1940)

View Set

Macroeconomics Exam 2 Study Guide

View Set

Chapter 1: Becoming a Public Speaker

View Set