Docsity

SAS 9.4 Base Programming: Creating and Managing SAS Data Sets, Exams of Technology

Toggle sidebar
bg1
A00-231 SAS 9.4 Base Programming -- Performance-based
Exam
1
1. Which statement is used to create a new SAS data set in a DATA step from an
existing SAS data set?
A. PROC DATA
B. DATA data=...
C. SET
D. DATA
Answer: D
Explanation:
ā— You typically use a DATA statement to define the name of a SAS data set you want to
create. The SET statement is used inside the DATA step to read the observations from
an existing data set, but the statement that begins the creation of a new data set is
DATA. For example:
2.When creating a permanent SAS data set, which element is essential?
A. A valid FILENAME statement
B. A user-assigned library reference (LIBNAME)
C. The WORK library reference
D. The ODS statement
Answer: B
Explanation:
ā— To create a permanent SAS data set, you must write the data set to a library that is not
the temporary WORK library. This requires assigning a library reference (LIBNAME) to
a permanent folder/directory.
3.Which option correctly demonstrates creating a permanent data set named employees
in the library mylib from an existing data set work.staff?
A.
sas
Copy
DATA employees;
SET mylib.staff;
RUN;
B.
sas
Copy
DATA mylib.employees;
SET work.staff;
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download SAS 9.4 Base Programming: Creating and Managing SAS Data Sets and more Exams Technology in PDF only on Docsity!

Exam

1. Which statement is used to create a new SAS data set in a DATA step from an

existing SAS data set? A. PROC DATA B. DATA data=... C. SET D. DATA Answer: D Explanation:

ā— You typically use a DATA statement to define the name of a SAS data set you want to

create. The SET statement is used inside the DATA step to read the observations from an existing data set, but the statement that begins the creation of a new data set is DATA. For example:

2.When creating a permanent SAS data set, which element is essential?

A. A valid FILENAME statement B. A user-assigned library reference (LIBNAME) C. The WORK library reference D. The ODS statement Answer: B Explanation:

ā— To create a permanent SAS data set, you must write the data set to a library that is not

the temporary WORK library. This requires assigning a library reference (LIBNAME) to a permanent folder/directory.

3.Which option correctly demonstrates creating a permanent data set named employees

in the library mylib from an existing data set work.staff? A. sas Copy DATA employees; SET mylib.staff; RUN; B. sas Copy DATA mylib.employees; SET work.staff;

Exam

RUN; C. sas Copy DATA work.mylib.employees; SET staff; RUN; D. sas Copy DATA mylib_work.employees; SET staff; RUN; Answer: B Explanation:

ā— To create a permanent data set, you must use the two-level name: mylib.employees.

The SET statement reads from work.staff, and the newly created data set is in the mylib library.

4.By default, if you do not specify a library name when creating a new data set, SAS

stores it in which library? A. USER B. WORK C. PERM D. TEMP Answer: B Explanation:

ā— When no library reference is specified, SAS automatically places the data set in the

temporary WORK library, which is deleted at the end of the SAS session.

5.When writing a DATA step, where should the SET statement typically appear if you

want to copy data from an existing data set? A. Right before the RUN; statement B. After the DATA statement and before other statements C. Anywhere in the DATA step D. It cannot be used in the same DATA step as other statements

Exam

ā— In the DATA step, you used only one-level naming (employees). SAS defaults to the

WORK library unless otherwise specified. The SET mydata.staff; reads from the permanent library mydata, but the output (employees) is in WORK.

9.Which statement is true about using a two-level name in the DATA statement but a one-

level name in the SET statement? A. It will convert the input data set into a temporary data set automatically. B. It will produce an error message and the code will not execute. C. It will produce a permanent data set while reading from a temporary one. D. It will produce a temporary data set while reading from a permanent one. Answer: C Explanation:

ā— Specifying a two-level name (e.g., mylib.newds) in the DATA statement creates a

permanent data set in mylib, while specifying a one-level name (e.g., oldds) in the SET statement points to the default WORK.oldds. This means you read from a temporary data set and write to a permanent one.

10.Which of the following is true about the WORK library in SAS?

A. It requires a LIBNAME statement to be referenced. B. It does not exist unless you create it manually. C. It is automatically created at the start of the session and deleted at the end. D. It stores only logs and output files. Answer: C Explanation:

ā— The WORK library is a temporary library automatically created by SAS at the beginning

of a session and removed at session termination.

11.When referencing a permanent data set with a LIBNAME of sales and a data set

name of region, how should it be referred to in a DATA step? A. sales.region.sas7bdat B. sales(region) C. region.sales D. sales.region Answer: D Explanation:

Exam

ā— The correct two-level naming format is libref.dataset, i.e., sales.region. SAS

automatically appends the .sas7bdat extension for datasets in most environments.

12.What is the result of running the following code?

A. It creates a new data set in the WORK library. B. It overwrites the existing mylib.emps data set with the same data. C. It renames mylib.emps to emps2 in the same library. D. It produces an error since you can't read and write the same data set simultaneously. Answer: B Explanation:

ā— By default, using the same library and data set name in both the DATA statement and

the SET statement overwrites the existing data set with the new data (which, in this case, is identical unless additional statements modify it).

13.Which of the following is the correct syntax to create a new data set temp_data in the

WORK library from an existing data set mylib.source_data? A. sas Copy DATA WORK.mylib.temp_data; SET source_data; RUN; B. sas Copy DATA mylib.temp_data; SET WORK.source_data; RUN; C. sas Copy DATA temp_data; SET mylib.source_data; RUN; D. sas

Exam

A. Use a DATA statement without the SET statement. B. Place all attribute-related statements (e.g., LENGTH, FORMAT, etc.) before the SET statement. C. Use PROC CONTENTS to change attributes. D. Use PROC APPEND to finalize changes. Answer: B Explanation:

ā— Attributes like LENGTH and FORMAT must be specified before the SET statement for

them to take effect in the output data set during that DATA step.

17.What is a valid reason to overwrite an existing permanent SAS data set with a

DATA step? A. To rename the dataset to something more meaningful B. To add new observations or modify existing variables C. To delete the dataset from the disk D. Overwriting permanent data sets is not allowed in SAS Answer: B Explanation:

ā— Overwriting is often done to replace or update a data set with new or modified

information. However, caution should be used since it destroys the original data set.

18.In order to write data to a data set in a permanent library named testlib, which of

the following could be a valid statement in a DATA step? A. DATA testlib dataset; SET olddata; B. DATA testlib.olddata; C. DATA testlib.newset; SET olddata; D. DATA newset.testlib; Answer: C Explanation:

ā— The correct two-level name for the output dataset is testlib.newset. The SET

olddata can reference a one-level name if olddata is in the WORK library or another two-level name if it is in a different library.

Exam

19.If you want to create a new data set class_subset from sashelp.class in the WORK

library, which is the simplest code snippet? A. sas Copy LIBNAME WORK 'C:\temp'; DATA class_subset; SET WORK.class; RUN; B. sas Copy DATA class_subset; SET sashelp.class; RUN; C. sas Copy DATA WORK.class_subset; SET class; RUN; D. sas Copy DATA class_subset; SET class; RUN; Answer: B Explanation:

ā— sashelp.class is a permanent dataset available by default. Using one-level naming

(class_subset) stores the output in WORK.class_subset. This is the simplest code.

20.Which of the following is typically not a recommended step when creating a

permanent SAS data set? A. Checking available disk space in the target library location B. Adding relevant LABEL or FORMAT statements to clarify data C. Including a KEEP= or DROP= data set option if needed D. Saving the data set to the WORK library

Exam

Answer: A Explanation:

ā— LIBNAME mylib 'C:\Data'; is the proper statement to assign a library reference

named mylib to the directory C:\Data.

23.What would be an appropriate way to clear the library reference sales in SAS?

A.

sas Copy LIBNAME sales CLEAR; B. sas Copy FILENAME sales CLEAR; C. sas Copy PROC CLEAR lib=sales; RUN; D. sas Copy LIBFILE sales CLEAR; Answer: A Explanation:

ā— To unassign or clear a library reference, you use LIBNAME sales CLEAR;.

24.Which procedure can you use to explore all data sets within a library and their

attributes (e.g., creation date, variables)? A. PROC FREQ B. PROC UNIVARIATE C. PROC CONTENTS D. PROC PRINT

Exam

Answer: C Explanation:

ā— PROC CONTENTS is used to display information about the structure of SAS data sets,

including variable attributes, the number of observations, and more.

25.Which PROC CONTENTS statement is the best practice to show metadata for all

data sets in the mylib library? A. sas Copy PROC CONTENTS DATA=mylib.ALL NODS; RUN; B. sas Copy PROC CONTENTS DATA=mylib; RUN; C. sas Copy PROC CONTENTS DATA='mylib'; RUN; D. sas Copy PROC CONTENTS LIBNAME=mylib ALL; RUN; Answer: A Explanation:

ā— Using DATA=mylib.ALL instructs SAS to display contents of all data sets in the

mylib library. The NODS option suppresses the detailed descriptor for each data set, providing a succinct summary.

26.When you submit a PROC CONTENTS DATA=mylib.ALL; RUN; statement, what is the

primary piece of information you will not see by default? A. Number of observations in each data set

Exam

28.To view the location on your computer or network assigned to a library reference,

you can check which of the following? A. The SAS log after submitting a LIBNAME statement B. The SASHELP.VTABLE view C. The PROC CONTENTS NODS listing D. The PROC PRINT output of the library Answer: A Explanation:

ā— When you submit a LIBNAME statement, the SAS log typically displays the physical

path associated with that libref. You can also query SASHELP.VLIBNAM to see library assignments, but the simplest place to check is the SAS log.

29.What will happen if you attempt to assign a library reference to a path that does not

exist? A. SAS creates the folder automatically. B. SAS displays an error in the log, and the libref is not assigned. C. SAS assigns the libref to the closest existing directory. D. The session hangs indefinitely. Answer: B Explanation:

ā— If the path in your LIBNAME statement is invalid, SAS typically posts an error to the

log and does not assign the library reference.

30.Which of the following is true about PROC CONTENTS?

A. You cannot use it on the WORK library. B. It provides a listing of the data itself, including observation-level data. C. It only works on permanent libraries. D. It describes the structure (descriptor portion) of the data sets. Answer: D Explanation:

ā— PROC CONTENTS displays descriptor information (structure) of the data sets, such as

variable names, lengths, labels, creation date, and so on, not the actual data values.

Exam

31.If you want to see a quick listing of all columns in mylib.sales and their attributes,

which procedure is most efficient? A. PROC FREQ B. PROC PRINT C. PROC CONTENTS D. PROC SQL Answer: C Explanation:

ā— PROC CONTENTS is purpose-built to display column attributes for a given data set.

32.When using PROC CONTENTS, which of the following statements about the output is

correct? A. It displays only numeric variables by default. B. It shows the file format (e.g., .xlsx, .csv) that the data set was sourced from. C. It displays variable type, length, label, and format for each variable. D. It automatically sorts the variables by name or label. Answer: C Explanation:

ā— PROC CONTENTS provides metadata including variable type, length, label, and format.

It does not indicate the original file format.

33.Which is the correct way to run PROC CONTENTS on the mylib library without

showing detailed variable attributes for each data set? A. sas Copy PROC CONTENTS DATA=mylib.ALL; RUN; B. sas Copy PROC CONTENTS DATA=mylib.ALL NODS; RUN; C. sas Copy

Exam

36.If you want to see the number of observations in mylib.sales without printing all

the data, which approach might you use? A. PROC PRINT DATA=mylib.sales (OBS=0); B. PROC SQL; SELECT COUNT(*) FROM mylib.sales; QUIT; C. PROC CONTENTS DATA=mylib.sales; RUN; D. Any of the above Answer: D Explanation:

ā— All listed methods can reveal the total number of observations without printing all of

them: o PROC PRINT DATA=mylib.sales (OBS=0) shows dataset attributes (including # of observations) but does not print rows. o PROC SQL; SELECT COUNT(*) returns the row count. o PROC CONTENTS shows the number of observations in the metadata.

37.Which library is automatically assigned by SAS at startup and contains sample data

sets, such as class? A. WORK B. SASHELP C. MAPS D. USER Answer: B Explanation:

ā— The SASHELP library is a permanent SAS library supplied by SAS that contains

sample data sets and utility files.

38.To store user-created data sets permanently in SAS without reassigning the same

library reference every session, you can: A. Add the LIBNAME statement to the Autoexec file. B. Use a macro variable that references the path. C. Use the WORK library for permanent storage. D. Manually assign the libref each time you start SAS. Answer: A Explanation:

ā— By placing the LIBNAME statement in your SAS Autoexec file, it runs automatically at

the start of each SAS session, ensuring a permanent library is always assigned.

Exam

39.What would happen if you run PROC CONTENTS DATA=mylib.ALL; RUN; but mylib

has no data sets? A. It produces an error message and stops. B. It displays a note in the log that there are no data sets in the library. C. It automatically creates a new data set called ALL. D. SAS tries to create an empty data set in mylib. Answer: B Explanation:

ā— If the library is valid but empty, SAS generally displays a note indicating no data sets

exist and no contents are displayed.

40.When assigning a library reference, which of the following can cause an error?

A. Using forward slashes on some operating systems B. The directory path does not exist or is misspelled C. Using an 8-character libref with uppercase letters D. Specifying the library reference as the first statement in the session Answer: B Explanation:

ā— A misspelled or non-existent directory path will cause an error. Other options (like

using forward slashes or an 8-character name) typically do not cause errors (depending on OS).

41.Which statement is used to read data from an existing SAS data set in a DATA step?

A. IF

B. SET

C. WHERE

D. INFILE

Answer: B Explanation:

ā— The SET statement reads observations from an existing SAS data set in a DATA step.

Exam

44.Which option ensures that an imported CSV file overwrites an existing SAS data set

of the same name if it already exists? A. REWRITE B. OVERWRITE C. REPLACE D. DELETE Answer: C Explanation:

ā— The REPLACE option in PROC IMPORT ensures any existing SAS data set with the same

name is overwritten.

45.Which statement about importing Excel files using the SAS/ACCESS XLSX engine

is correct? A. You must save the Excel file as a CSV first. B. The XLSX engine can directly read .xlsx files without using PROC IMPORT. C. It only works on Unix-based systems. D. It cannot access multiple sheets in the workbook. Answer: B Explanation:

ā— The SAS/ACCESS XLSX engine enables you to directly read or write .xlsx files

using a LIBNAME statement, bypassing the need for PROC IMPORT.

46.Which is the correct LIBNAME statement to assign a libref named exceldata to an

Excel workbook C:\Data\report.xlsx using the XLSX engine? A. sas Copy LIBNAME exceldata XLSX 'C:\Data\report.xlsx'; B. sas Copy LIBNAME exceldata 'C:\Data\report.xlsx' ENGINE=XLSX; C.

Exam

sas Copy LIBNAME exceldata 'C:\Data\report.xlsx' DBMS=XLSX; D. sas Copy FILENAME exceldata XLSX 'C:\Data\report.xlsx'; Answer: A Explanation:

ā— The correct syntax is LIBNAME exceldata XLSX 'C:\Data\report.xlsx';. This

tells SAS to treat the Excel file as a library with the XLSX engine.

47.After assigning a libref to an Excel workbook via the XLSX engine, how do you

reference a specific sheet named Sheet1 as a SAS data set? A. exceldata.Sheet1.sas7bdat B. exceldata."Sheet1"$ C. exceldata.'Sheet1$' D. exceldata.Sheet1$ Answer: D Explanation:

ā— When referencing sheets in Excel using the XLSX engine, you typically append a $ to

the sheet name: libref.SheetName$. If the sheet name has spaces, you would need quotes, e.g., exceldata.'My Sheet$'n.

48.When reading from an Excel sheet using the XLSX engine, which statement is not

true? A. You can use PROC CONTENTS to view the column metadata of the Excel sheet. B. You can filter rows using a WHERE statement in a DATA step. C. You can update data in the Excel file if you have write access. D. The Excel sheet is treated exactly like a native SAS dataset, including full indexing support. Answer: D Explanation:

ā— While the XLSX engine allows you to treat the Excel sheet similarly to a SAS data

set, not all SAS dataset features (like indexing) are fully supported for Excel files.