4: Preparing Data Flashcards
Which DATA step creates a permanent output data set?
a. data storm_new; set pg1.storm_summary; run; b. data out.storm_new; set pg1.storm_summary; run; c. data work.storm_new; set pg1.storm_summary; run;
B
This DATA step creates the storm_new table in the OUT library.
Which data sources can be used in the SET statement? Select all that apply.
a. SAS tables b. Excel spreadsheets c. DBMS tables d. comma-delimited files
A,B,C
Any data source that can be read via a library can be used as the input table in the SET statement.
In which phase does the DATA step check for syntax errors?
a. compilation b. execution
A
Checking for syntax errors is the first step in the compilation phase.
Which statement is used to read a SAS data set in a DATA step?
a. DATA statement b. WHERE statement c. SET statement d. assignment statement
C
The SET statement indicates the table that will be read. The DATA statement indicates the table that will be created or updated.
To process an Excel file with the DATA step, you must first create a copy of the data as a SAS table.
a. True b. False
B
You can use the XLSX LIBNAME engine to read an Excel worksheet directly and process the data with the DATA step.
What is the name of the ouput data set in the program below? data work.us; set orion.sales; where Country='US'; run;
a. work.us b. orion.sales c. Country d. sales
A
The output table is listed in the DATA statement.
The data set orion.sales contains nine columns. Given this DATA step, how many columns does work.comp have?
data work.comp;
set orion.sales;
keep employee_id status job_title salary;
run;
a. four b. nine c. five
A
Only the four columns listed in the KEEP statement are written to the work.comp table.
Given the assignment statement below, what is the value of AvgExp for the observation that is shown?
AvgExp=mean(Exp1, Exp2, Exp3, Exp4);
Exp1 Exp2 Exp3 Exp4
10 . 5 9
a. 6 b. 8 c. . (missing value) d. The statement generates a syntax error.
B
The MEAN function ignores missing values, so the calculation is (10+5+9)/3=8.
Which of the following SAS functions returns a number from 1 to 12?
a. YEAR(SAS-date-value) b. MONTH(SAS-date-value) c. WEEKDAY(SAS-date-value) d. none of the abov
B
The MONTH function returns the month number (1-12) extracted from a SAS date value.
in the program below, what is the value of Credit if Country is ‘au’?
data work.bonus;
set orion.sales;
if Country=’US’ then Credit=300;
else if Country=’AU’ then Credit=500;
else Credit=0;
run;
a. 300 b. 500 c. 0 d. missing
C
The character conditions are case sensitive. The first two IF conditions are false. Therefore, the final ELSE statement assigns Credit a value of zero.
What is the length of the Car_Type column created in this program?
data car_type;
set sashelp.cars;
if msrp>80000 then car_type=”luxury”;
else car_type=”regular”;
length car_type $ 8;
run;
a. 6 b. 7 c. 8
A
When the DATA step is compiled, the first mention of Car_Type determines the column name, type, and length. The length is determined by the value in the assignment statement. The value luxury has six characters, so the length is 6.
Use a DO group in a DATA step when you want to execute multiple statements for a true IF-THEN expression.
a. True b. False
A
To execute more that one statement if a condition is true, you must use IF-THEN/DO groups.