Ch 4: Creating SAS Data Sets Flashcards

1
Q

Which SAS statement associates the fileref Crime with the raw data file C:\States\Data\crime.dat?
a.
filename crime ‘c:\states\data\crime.dat’;
b.
filename crime c:\states\data\crime.dat;
c.
fileref crime ‘c:\states\data\crime.dat’;
d.
filename ‘c:\states\data\crime’ crime.dat;

A

Correct answer: a
You assign a fileref by using a FILENAME statement in the same way that you assign a libref by using a LIBNAME statement.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
Which type of delimited file does PROC IMPORT read by default?
a.
logical record-length files
b.
varying record-length files
c.
fixed record-length files
d.
illogical record-length files
A

Correct answer: b
By default, the IMPORT procedure reads delimited files as varying record-length files. If your external file has a fixed-length format, use the OPTIONS statement before the PROC IMPORT statement that includes the RECFM=F and LRECL= options.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
Which program correctly imports only the first seven lines from the external file that is delimited by a period (.) ? Hint: the first line in the external file contains variable names that you want to read in.
a.
options obs=7;
proc import data="C:\users\test.txt"
out=exam
dbms=dlm
replace;
getnames=yes;
run;
proc print data=exam;
run;
b.
options obs=7;
proc import datafile="c:\users\test.txt"
out=exam
dbms=dlm
replace;
delimiter='.';
getnames=yes;
run;
proc print data=exam;
run;
c.
proc import datafile="c:\users\test.txt"
out=exam
dbms=dlm
replace;
delimiter=' ';
getnames=no;
run;
proc print data=exam (obs=7);
run;
d.
proc import datafile="c:\users\test.txt"
out=exam
dbms=csv
replace;
delimiter=',';
getnames=no;
run;
proc print data=exam;
options obs=7;
run;
A

Correct answer: B
Use the OBS= option in the OPTIONS statement before the IMPORT procedure to limit the number of observations that SAS reads from the external file. When you use the OBS= option in the PROC PRINT statement, the whole file is imported but printing is limited to the number of observations specified. Use DELIMITER=’.’ to indicate that the delimiter is a period (.) and use GETNAMES=YES to read in the first line, which contains the variable names.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which of the following pieces of information does SAS need in the DATA step in order to read an Excel workbook file and write it out to a SAS data set?
a.
a libref to reference the Excel workbook to be read
b.
the name and location (using another libref) of the new SAS data set
c.
the name of the Excel worksheet that is to be read
d.
all of the above

A

Correct answer: d
To read an Excel workbook file, SAS must receive the following information in the DATA step: a libref to reference the Excel workbook to be read, the name and location (using another libref) of the new SAS data set, and the name of the Excel worksheet that is to be read.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
Which statement should you use if you want PROC IMPORT to generate SAS variable names from the values in the first row of an input file?
a.
getnames=no;
b.
datarow=1;
c.
guessingrows=1;
d.
getnames=yes;
A

Correct answer: d
The GETNAMES statement specifies whether the IMPORT procedure generates SAS variable names from the data values in the first row in the input file. The default is GETNAMES=YES. NO specifies that the IMPORT procedure generates SAS variable names as VAR1, VAR2, and so on.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
Which SAS program correctly imports data from an external file?
a.
filename workbook 'C:\certdata\class1.csv';
proc import datafile=workbook.class
dbms=csv
out=class1
replace;
getnames=yes;
run;
b.
filename workbook 'C:\certdata\workbook.txt';
proc import datafile=workbook
dbms=dlm
out=workbook
replace;
getnames=yes;
run;
c.
filename workbook 'C:\certdata\workbook.txt';
proc import datafile=class01
dbms=dlm
out=class01work
replace;
getnames=yes;
run;
d.
all of the above.
A

Correct answer: b
When you associate a fileref with an individual external file, you specify the fileref in subsequent SAS statements and commands.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Which delimited input file can be imported using PROC IMPORT?
a.
Region&State&Month&Expenses&Revenue
Southern&GA&JAN2001&2000&8000
Southern&GA&FEB2001&1200&6000
Southern&FL&FEB2001&8500&11000
Northern&NY&FEB2001&3000&4000
Northern&NY&MAR2001&6000&5000
Southern&FL&MAR2001&9800&13500
Northern&MA&MAR2001&1500&1000
b.
“Africa”,”Boot”,”Addis Ababa”,”12”,”$29,761”,”$191,821”,”$769”
“Asia”,”Boot”,”Bangkok”,”1”,”$1,996”,”$9,576”,”$80”
“Canada”,”Boot”,”Calgary”,”8”,”$17,720”,”$63,280”,”$472”
“Eastern Europe”,”Boot”,”Budapest”,”22”,”$74,102”,”$317,515”,”$3,341”
“Middle East”,”Boot”,”Al-Khobar”,”10”,”$15,062”,”$44,658”,”$765”
“Pacific”,”Boot”,”Auckland”,”12”,”$20,141”,”$97,919”,”$962”
“South America”,”Boot”,”Bogota”,”19”,”$15,312”,”$35,805”,”$1,229”
“United States”,”Boot”,”Chicago”,”16”,”$82,483”,”$305,061”,”$3,735”
“Western Europe”,”Boot”,”Copenhagen”,”2”,”$1,663”,”$4,657”,”$129”
c.
Region State Capital Bird
South Georgia Atlanta ‘Brown Thrasher’
South ‘North Carolina’ Raleigh Cardinal
North Connecticut Hartford Robin
West Washington Olympia ‘American Goldfinch’
Midwest Illinois Springfield Cardinal
d.
all of the above

A

Correct answer: d
The IMPORT procedure reads data from an external data source and writes it to a SAS data set. In delimited files, a delimiter (such as a blank, comma, or tab) separates columns of data values. You can also have a delimiter other than blanks, commas, or tabs. In those cases, PROC IMPORT reads the data from the external data source as well. You can have a delimiter such as an ampersand (&).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
To override the DATA step default behavior that writes observations to output, what should you use in a DATA step?
a.
DROP= and KEEP= data set options
b.
an OUTPUT statement
c.
an OUT= option
d.
a BY statement
A

Correct answer: b
Placing an explicit OUTPUT statement in a DATA step overrides the automatic output, so that observations are added to a data set only when the explicit OUTPUT statement is executed. The OUTPUT statement overrides the default behavior of the DATA step.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly