• No results found

DATA NEW; SET TEMP;

In document Advanced SAS 9 ExamPrep SritejGunta (Page 45-48)

OPTIONS MLOGIC | NOMLOGIC;

B. DATA NEW; SET TEMP;

IF A=8 THEN b=’SMALL’;

ELSE IF A IN(1,2) THEN B=’MEDIUM’; ELSE IF A=6 THEN B=’LARGE’; RUN;

B. DATA NEW; SET TEMP;

IF A IN(1,2) THEN B=’MEDIUM’; ELSE IF A=8 THEN B=’SMALL’;

ELSE IF A=6 THEN B=’LARGE’; RUN;

C. DATA NEW; SET TEMP;

IF A=6 THEN B=’LARGE’;

ELSE IF A IN(1,2) THEN B=’MEDIUM’; ELSE IF A=8 THEN B=’SMALL’; RUN;

D. DATA NEW; SET TEMP;

IF A=6 THEN B=’LARGE’; IF A IN(1,2) THEN B=’SMALL’; RUN;

91. (C) You can immediately dismiss option (D) because the %QUOTE function masks special characters and mnemonic operators in a resolved value at macro execution, it doesn’t put quotation marks around a character string. The other three options simply involve properly resolving the macro variable to the appropriate value. Refer to the explanations for 57 and/or 67 if you need a refresher on how to do that.

92. (C) In order to create a random sample, you need to generate a random number. SAS provides several random number functions to generate random numbers from various distributions. One such example is the RANUNI function. RANUNI (seed)

Where seed is a nonnegative integer with a value less than 231-1 (2,147,483,647)

The RANUNI function generates streams of random numbers from an initial starting point, called the seed. If you use a positive seed, you can always replicate the stream of random numbers by using the same data step. If you use 0 as the seed, the computer clock initializes the stream, and the stream of random numbers is not replicable.

Therefore, because this example is used with a seed of 123, there is a consistent sequence.

93. (B) First, notice that a macro variable called DEVELOPMENT with a value of ontime has been created via a LET statement.

The question requires that TITLE1 print a value that includes an ampersand (&) with the word development immediately after. Without any addition to the code, that title would resolve to “For researchontime”.

Sometimes you might want to hide the normal meaning of an ampersand or a percentage sign. The %NRSTR function performs the same quoting functions %STR, except it also masks macro triggers (& and %). The NR in the name %NRSTR stands for No Resolution.

94. (A) The WHERE statement examines what is in the input page buffer and selects observations before they are loaded in the program data vector, which results in a savings in CPU operations.

95. (D) SAS executes a view each time it is referenced, even within one program. Therefore, if data is used many times in one program, it is more efficient to create and reference a temporary SAS data file than to create and reference a view.

96. (C) When referencing a macro function within a LET statement, the percentage sign (%) must be used. Therefore, you can immediately eliminate options (A) and (D).

The %SUBSTR function enables you to extract part of a character string from the value of a macro variable. The syntax is as follows:

%SUBSTR (argument, position<,n>)

Advanced SAS 9 Exam Prep: A00-212 | Prepared for Sritej Gunta position is an integer or an expression (text, logical, or mathematical) that yields an integer, which specifies the position of the first character in the substring.

n is an optional integer or an expression (text, logical, or mathematical) that yields an integer that specifies the number of characters in the substring.

If the length of n is greater than the number of characters following position in argument, %SUBSTR issues a warning message and returns a substring that contains the characters from position to the end of the string. If n is not specified, %SUBTR also returns a substring that contains the characters from position to the end of the string. The %LENGTH function returns the length of a string. The syntax is as follows:

%LENGTH (character string | text expression)

If the argument is a character string, %LENGTH returns the length of the string. If the argument is a text

expression, %LENGTH returns the length of the resolved value. If the argument has a null value, %LENGTH returns 0. The values of position and n can also be the result of a mathematical expression that yields an integer.

So, in this example we are given the macro variable IDCODE with a value of PROD567. Our task is to create another macro variable called CODENUM with a value of 567.

In this instance, the %SUBSTR function references the value of the macro variable IDCODE (PROD567) as the argument. The position that is to be extracted is a mathematical expression which utilizes the %LENGTH function.

%LENGTH is calling on the numerical length of the value of the macro variable IDCODE (which is 7). It is 7 because that’s how many characters are in the value (P R O D 5 6 7).

Now, the mathematical expression tells the %SUBSTR function where to begin extracting the character string. We want to extract the value of 567 from PROD567. So, in order to do that, our code must reference the fifth position. The %LENGTH function gives us the value of 7. If we subtract 2 from 7, we have 5. Therefore, option (C) is the correct answer.

Note: If the code had instead been:

%LET CODENUM=%SUBSTR(&IDCODE, %LENGTH(&IDCODE)-3);

Then the value of the macro variable CODENUM would have been D567. 7 minus 3 would have begun the %SUBTR extraction in position 4.

If the code had instead been:

%LET CODENUM=%SUBSTR(&IDCODE, %LENGTH(&IDCODE)-5);

Then the value of the macro variable CODENUM would have been ROD567. 7 minus 5 would have begun the %SUBTR extraction in position 2.

97. (C) This program produces error and warning messages because when it attempts to overlay the variable SALES, SALES is a numeric variable in data set ONE and a character variable in data set TWO. In order to merge, variables of the same name must also be of the same type.

98. (A) In the example, the CREATE TABLE statement creates a table (data set) named THREE and populates the variables from the SELECT statement via the AS keyword.

The result is an INNER JOIN based on the conditions in the WHERE statement which output a Cartesian product of four total observations where the values in the NUM column are all equal to 2.

The DATA step that replicates this output is option (A).

99. (C) This code creates a numeric format called TEMPC.

The question asks, "How is the value 10 displayed when the format TEMPC is applied?"

The "less-than" operator (<) is used to show a non-inclusive range. However, the side on which the hyphen falls determines which of the two values is included and which is excluded.

For the label BELOW FREEZING, because the hyphen is on the left side of the less-than operator (range: LOW -< 0). This means that the exact value of zero is non-inclusive in the range.

For the label MILD (range: 5 -< 10), the value 10 is non-inclusive.

For the label WARM (range: 10 -< 15), the value 15 is non-inclusive. Therefore, if the value is 10, the label would be WARM.

Note: You can switch the hyphen to the other side of the less-than operator and switch the properties.

For example, if the label WARM had a range such that (range: 10 <- 15), then the value 10 would be non-inclusive and the value 10 would no longer have the label WARM but instead MILD (if the same logic were applied to the MILD label).

100. (C) Because the value 6 is the most prevalent, it is most likely that for any given observation of variable A, the value will be 6. Therefore, it is most efficient to first evaluate an IF statement assuming the first value is 6. This eliminates options (A) and (B) immediately.

The next thing to do is assign values to the next largest frequency values (1 and 2). Both options (C) and (D) do this, but the use if the ELSE statements allows SAS to accomplish this in one sweep.

Therefore, option (C) is most efficient in terms of computer processing.

101. The SAS data set ONE is given below: DIVISION SALES

--- --- A 1234 A 3654 B 5678

The following SAS program is submitted: DATA _NULL_; SET ONE; BY DIVISION; IF FIRST.DIVISION THEN DO; %LET MFIRST=SALES; END; RUN;

What is the value of the macro variable MFIRST when the program finishes execution? A. 1234

B. SALES C. 5678 D. NULL

102. The SAS data set ONE has a variable, X, on which an index has been created. The data sets ONE and THREE are sorted by X.

Which one of the following SAS programs uses the index to select observations from the data set ONE? A. DATA TWO;

SET THREE; SET ONE KEY=X; RUN;

In document Advanced SAS 9 ExamPrep SritejGunta (Page 45-48)

Related documents