Lesson 2: Accessing Data Flashcards

1
Q

Syntax to view / readtable and column a
attributes

A

PROC CONTENTS DATA=data-set;
RUN;

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

Syntax to create a Library

A

LIBNAME - libref - engine - “path”;

LIBNAME - key word
libref - name of your library
engine - (base is default, can be omitted)
path - found in Properties

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

Syntax to delete library Ref

A

LIBNAME libref CLEAR;

libref if your LIBRARYNAME

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

Syntax to use PROC step with Library Ref

A

PROC CONTENTS DATA = LIBRARYNAME.FILENAME;
RUN;

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

What kind of statement is LIBNAME? Does it need a RUN statement?

A

LIBNAME statement is a global statement and does not need a RUN statement at the end.

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

What are LIBNAME name attributes?

A
  • The libref must be 8 characters or less
  • must start with either a letter or underscore
  • includes only letters, numbers, and underscores
  • the path must also be in quotation marks
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to access tables (data) in your library?

What is the syntax?

A

PROC CONTENTS DATA = libref.table-name

You use the library to access tables in your program by specifying
- the libref (or library name)
- a period and
- the table name (mylib.class).

You don’t have to type the file extension because SAS already knows you’re accessing SAS tables from that location.

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

Work Library

A

WORK library is default, automatic and temporary; all tables deleted at the end of the session.

Tables stored in the Work library are deleted at the end of each SAS session.

Work is the default library, so if a table name is provided in the program without a libref, the table will be read from or written to the Work library.

DATA=WORK.TEST
DATA=TEST

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

SASHELP Library

A

SASHELP is automatic and contains collection of sample tables and other data.

The library is automatically available when SAS starts.

DATA=SASHELP.CARS

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

Syntax to use library to READ data directly from Excel workbooks?

A

LIBNAME libref XLSX “path/file-name.xlsx”;

LIBNAME - keyword
libref - name of your library
XLSX - engine to READ Excel

The full path to the Excel file, including the .xlsx file extension, must be provided in DOUBLE quotation marks.

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

Importing unstructured data

A

You must import the data into a structured format, such as a SAS table, before you can use the data in a program. SAS can import delimited files with any character acting as the delimiter. By default, SAS assumes column names are found in the first row of the file.

PROC IMPORT
DATAFILE=”path/filename” DBMS=filetype
OUT=output-table
REPLACE
GUESSINGROWS=n|MAX;
RUN;

PROC IMPORT reads data from an external data source and writes it to a SAS data set.

DATAFILE= path and complete file name

DBMS= defines the file type (e.g. cvs, txt)

OUT= library and name of the SAS output table

REPLACE overwrites the SAS output table if it already exists

GUESSINGROWS=provides a number of rows to examine. By default it scans the first 20 rows

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

Importing Excel Files

A

Imports a copy of Excel data as a SAS table and uses that SAS table in your program.

PROC IMPORT can read only one spreadsheet at a time, and by default it reads the first worksheet.

PROC IMPORT DATAFILE=”path/file-name.xlsx”
DBMS=XLSX
OUT=output-table <REPLACE>;
SHEET=sheet-name;
RUN;</REPLACE>

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

What portions do SAS data sets have?

A

DATA and DESCRIPTOR

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

What are the three types of SAS columns?

A

Name, Type, and Length.

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

Columns are either

A

character or numeric

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

Character columns can have a length

A

between 1 and 32,767 bytes (1 byte = 1 character).

18
Q

Numeric columns are stored with a length of

A

8 bytes.

19
Q

Character columns can consist

A

letters, numbers, special characters, or blanks.

20
Q

Numeric columns can consist of

A

digits 0-9, minus sign, decimal point, and E for scientific notation.

21
Q

SAS date values are a type of numeric value and represent the number of days between

A

January 1, 1960, and a specified date

22
Q

What is LIBREF

A

is the name of the library that can be used in a SAS program to read data files.

23
Q

What does ENGINE do?

A

provides instructions for reading SAS files and other types of files.

24
Q

What does PATH do?

A

provides the directory where the collection of tables is located.

25
Q

The LIBREF remains active until

A

you clear it, delete it, or shut down SAS.

LIBNAME libref engine “path”;
LIBNAME libref CLEAR;

26
Q

The XLSX engine enables

A

to read data directly from Excel workbooks. The XLSX engine requires the SAS/ACCESS to PC Files license.

27
Q

The VALIDVARNAME=V7 system option forces

A

table and column names read from Excel to adhere to recommended SAS naming conventions.

Spaces and special symbols are replaced with underscores, and names greater than 32 characters are truncated.

28
Q

Date values are automatically converted

A

to numeric SAS date values and formatted for easy interpretation

29
Q

Worksheets or named ranges from the Excel workbook can be referenced in a SAS program as

A

libref.spreadsheet-name.

30
Q

other databases, it’s a good practice to delete the libref at the end of your program with WHAT option?

A

CLEAR

OPTIONS VALIDVARNAME=V7;
LIBNAME libref XLSX “path/file.xlsx”;

31
Q

The DBMS option identifies

A

the file type.
The CSV value is included with Base SAS.

32
Q

The OUT= option provides

A

the library and name of the SAS output table

33
Q

The REPLACE option is necessary to

A

overwrite the SAS output table if it exists.

34
Q

SAS assumes that column names are in the

A

1st line of the text file and data begins on the second line

35
Q

Date values are automatically converted to

A

numeric SAS date values and formatted for easy interpretation

36
Q

The GUESSINGROWS= option indicates the

A

number of rows the IMPORT procedure scans in the input file to determine the appropriate data type and length of columns. The default value is 20 and the allowed range is 1 to 2147483647 (or MAX).

37
Q

Syntax for importing CSV file is

A

PROC IMPORT DATAFILE=”file.csv”
DBMS=CSV
OUT=output-table REPLACE;
GUESSINGROWS=n;
RUN;

38
Q

Syntax for Importing an Excel (XLSX) File

A

PROC IMPORT DATAFILE=”file.xlsx” DBMS=XLSX
OUT=output-table REPLACE;
SHEET=sheet-name;
RUN;

39
Q

Missing numeric values are represented

A

with a period

40
Q
A