Reading and Formatting SAS Data Sets Flashcards

1
Q

Format statement. What is it under?

A

FORMAT variable(s) format;

Under PROC PRINT

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

What date has the SAS date value of zero?

A

Jan 1, 1960

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

How to create your own format?

A

PROC FORMAT;

VALUE format-name value-or-range1= ‘formatted-value1’

value-or-range2=’formatted-value2’

…..;

RUN;

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

Rules for format name

A
  1. Max of 32 characters
  2. If format is for character values, the name begins with $
  3. Begin with letter or underscore.
  4. Cannot end on a number
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you exclude the highest or lowest number from a range (when you’re making own format)?

A

1<-10 excludes 1

1-<10 excludes 10

Note: Cannot use > sign

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

What keywords can you use in a range (while making on format) if you don’t know the highest or lowest values in the data set?

A

low (for lowest value)

high (for highest value)

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

How to you make a new data set that’s a subset of another data set?

A

DATA output-SAS-data-set;

SET input-SAS-data-set;

WHERE variable=condition;

RUN;

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

How can you compare a SAS date value to a calendar date?

A

Use SAS Date Constant instead of the SAS date value:

‘ddmmm(yy)yy’D

e.g. ‘01JAN2000’D

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

How do you create a new variable or assign a value to an existing variable?

A

Use assignment statement:

variable=expression;

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

What happens if a variable in an arithmetic expression has a missing value?

A

The result is a missing value

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

How do you exclude variables from a data set?

A

DROP variables;

KEEP variables;

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

What happens in the Compilation Phase of a DATA step?

A
  1. SAS scans each DATA step statement for syntax errors. Converts program into machine code if no errors are found.
  2. Creates program data vector (PDV), which contains variables in new data set as well as variable type and length.
  3. Creates description portion of new data set (contains data set name and names of all variables)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What happens in the Execution Phase of a DATA Step?

A

SAS reads and processes observations from input data set.

  1. SAS initializes the PDV to missing
  2. When SET statement executes, SAS reads the first observation from input data set into the PDV (with all variables and values)
  3. Creates new variable values

Creates observations in the data portion of the output data set

  1. Uses values in PDV to write the first observation to the new SAS data set.
  2. Drops any variables or observations specified
  3. Then, returns to top of DATA step for next observation and repeats process
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What happens if you use the WHERE statement to include a variable that you created (it’s not on the original data set)? What can you do instead?

A

ERROR. SAS can’t read the variable because is not on the original data set.

Use IF expression;

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

How is WHERE statement different from IF?

A
  • Cannot use special WHERE operators with IF
  • Cannot use IF with a PROC Step
  • Can always use IF in a DATA Step
  • Can only use WHERE in a DATA Step with variables that are in the input data set
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you assign permanent labels?

A

Use LABEL variable=’label’; in a DATA Step rather than a PROC step. Remember to still add label to PROC print step

17
Q

How to add permanent formats?

A

Use FORMAT statment within DATA step

18
Q

General form of SAS formats

A

($)formatname(w).(d)

$ is for character formats

w is total width

d specifies decimal places for numeric formats