Question : The contents of the raw data file AMOUNT are listed below:
--------10-------20-------30 $1,234 The following SAS program is submitted: data test; infile 'amount'; input @1 salary 6.; if _error_ then description = 'Problems'; else description = 'No Problems'; run; Which one of the following is the value of the DESCRIPTION variable?
1. Problems 2. No Problems 3. ' ' (missing character value) 4. The value can not be determined as the program fails to execute due to errors
Correct Answer : 1
Explanation:As the program has an error IT IS DUE TO DATA ERROR. IN COMPILATION ERROR THE PROGRAMM STOP NOT EXECUTED. HERE THE PROGRAMM EXECUTE FULLY WITH ERROR IN LOG WINDOW.
Reason: Input statment should be like below; input @1 salary dollar6.; or input @1 salary comma6.; informat provided in incorrect and sas cannot read $ and , symbols by giving 6
Incorrect informat in the input statement, salary is missing '.' during execution, the if statement executes, assigning the description text, with _error_ = 1.
B is ruled out, for another reason - because the length of the variable description is determined in the if statement by the character string first encountered: 'Problems' during compilation, so that if _error_ = 0 a truncated 'No Probl' (8 characters) would be stored in the variable and appear in the dataset not 'No Problems'
The DOLLARw.d format writes numeric values with a leading dollar sign, a comma that separates every three digits, and a period that separates the decimal fraction. Examples put @3 netpay dollar10.2; Value of netpay 1254.71 Results $1,254.71
Question : The contents of the raw data file NAMENUM are listed below:
--------10-------20-------30 Joe xx The following SAS program is submitted: data test; infile 'namenum'; input name $ number; run; Which one of the following is the value of the NUMBER variable? 1. xx 2. Joe 3. . (missing numeric value) 4. The value can not be determined as the program fails to execute due to errors.
Correct Answer : 3
Explanation: missing value, since a numeric value is expected for the variable been read, and a character value was found. You have given name as character and there was no delimiter means default space will be used as delimiter here. So name will read Joe and number is expecting numeric value but it reads xx, so number is set to missing. SAS encounters character data for numeric data and sets _error_=1. However, SAS still runs the code and generates an list file with name=Jeo and number is set to a missing value.
Question : Which one of the following statements is true regarding the SAS automatic _ERROR_ variable?
1. The _ERROR_ variable contains the values 'ON' or 'OFF'. 2. The _ERROR_ variable contains the values 'TRUE' or 'FALSE'. 3. The _ERROR_ variable is automatically stored in the resulting SAS data set. 4. The _ERROR_ variable can be used in expressions or calculations in the DATA step.
Correct Answer : 4
Explanation:
Automatic Variables Automatic variables are created automatically by the DATA step or by DATA step statements. These variables are added to the program data vector but are not output to the data set being created. The values of automatic variables are retained from one iteration of the DATA step to the next, rather than set to missing. Automatic variables that are created by specific statements are documented with those statements. Two automatic variables are created by every DATA step: _N_ and _ERROR_.
_N_ is initially set to 1. Each time the DATA step loops past the DATA statement, the variable _N_ increments by 1. The value of _N_ represents the number of times the DATA step has iterated.
_ERROR_ is 0 by default but is set to 1 whenever an error is encountered, such as an input data error, a conversion error, or a math error, as in division by 0 or a floating point overflow. You can use the value of this variable to help locate errors in data records and to print an error message to the SAS log. For example, either of the two following statements writes to the SAS log, during each iteration of the DATA step, the contents of an input record in which an input error is encountered: