Question : A SAS program is submitted and the following SAS log is produced: 2 data gt100; 3 set ia.airplanes 4 if mpg gt 100 then output; 22 202 ERROR: File WORK.IF.DATA does not exist. ERROR: File WORK.MPG.DATA does not exist. ERROR: File WORK.GT.DATA does not exist. ERROR: File WORK.THEN.DATA does not exist. ERROR: File WORK.OUTPUT.DATA does not exist. ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, ;, END, KEY, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_. ERROR 202-322: The option or parameter is not recognized and will be ignored. 5 run; The IA libref was previously assigned in this SAS session. Which one of the following corrects the errors in the LOG?
1. Delete the word THEN on the IF statement. 2. Add a semicolon at the end of the SET statement. 3. Place quotes around the value on the IF statement. 4. Add an END statement to conclude the IF statement
Correct Answer 2 :
Explanation: In SET statement semicolon is missing, so SAS is considering each word after SET as a separate data set which is creating an Error.
So placing the semicolon in SET statement will serve the purpose. What SET Does Each time the SET statement is executed, SAS reads one observation into the program data vector. SET reads all variables and all observations from the input data sets unless you tell SAS to do otherwise. A SET statement can contain multiple data sets; a DATA step can contain multiple SET statements. See Combining and Modifying SAS Data Sets: Examples.
Uses The SET statement is flexible and has a variety of uses in SAS programming. These uses are determined by the options and statements that you use with the SET statement: reading observations and variables from existing SAS data sets for further processing in the DATA step concatenating and interleaving data sets, and performing one-to-one reading of data sets reading SAS data sets by using direct access methods.
Question : The contents of the raw data file CALENDAR are listed below: --------10-------20-------30 The following SAS program is submitted: data test; infile 'calendar'; input @1 date mmddyy10.; if date = '01012000'd then event = 'January 1st'; run; Which one of the following is the value of the EVENT variable?
1. 01012000 2. January 1st 3. (missing numeric value) 4. The value cannot be determined as the program fails to execute due to errors.
Correct Answer 4 :
Explanation:
Formatted input enables you to supply special instructions in the INPUT statement for reading data. For example, to read numeric data that contains special symbols, you need to supply SAS with special instructions so that it can read the data correctly. These instructions, called informats
data total_sales; input Date mmddyy10. +2 Amount comma5.; In this example, the MMDDYY10. informat for the variable Date tells SAS to interpret the raw data as a month, day, and year, ignoring the slashes. The COMMA5. informat for the variable Amount tells SAS to interpret the raw data as a number, ignoring the comma. The +2 is a pointer control that tells SAS where to look for the next item.
However, SAS is also capable of reading two-digit year values (for example, 09/05/99). In this example, use the MMDDYY8. informat for the variable Date. Answer D is because date constant is invalid. [Evern after providing correct date constant -date='01JAN2000'd desired output not produced and it produces Note: SAS went to a new line when INPUT statement reached past the end of a line.] The error that shown even on your correction is probably because the informat given is wrong. The informat should be 'mmddyy8.'. Once you do that, the event shows up as January 1st
If we provide correct date contant date='01jan2000'd, will get the result. please try the below program.
data test; infile datalines; input @1 date mmddyy10.; if date = '01jan2000'd then event = 'January 1st'; datalines; ;
Question : The following SAS program is submitted:
data work.january; set work.allmonths (keep = product month num_sold cost); if month = 'Jan' then output work.january; sales = cost * num_sold; keep = product sales; run; Which variables does the WORK.JANUARY data set contain?
1. PRODUCT and SALES only 2. PRODUCT, MONTH, NUM_SOLD and COST only 3. PRODUCT, SALES, MONTH, NUM_SOLD and COST only 4. An incomplete output data set is created due to syntax errors
Correct Answer : 4
Explanation: As there is syntax error. "keep = product sales" which is the incorrect way to use KEEP option
It has syntax error is it due to 1) if month = 'Jan' then output work.january; or 2) keep = product sales;
For sure if it is with data line ( drop = variables) and no need = in the body separately.
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.