SAS P1 L5 Flashcards

1
Q

What does formatting do?

A

Formats control the way data is displayed.

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

FORMAT statement added to?

syntax?

what does it end with?

SAS has?

A

FORMAT statement is added to PROC PRINT
Syntax:
FORMAT variable_name format_name.;

note ends in period

SAS has lots of defined formats

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

How many variables per format statement?

A

Can specify multiple variables with same format statement, or can use separate format statement for each

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

What are formats, and what do they do?

A

Formats = instructions that tell SAS how to display data values

ex: using commas, dollar sign to display

$5,950.25 vs 5090.25

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

What is the form of existing formats?

how indicate character format?

field width?

decimal places?

A

form of exisiting formats:

{$}format{w}.{d}

where {$} indicates character format (omit if num)
and {w} indicates field width
and {d} indicates decimal places (if any)

(they use < and > instead of curly brackets)

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

examples of existing formats that:

  • write standard char data, width w
  • write standard num data, width w
  • write numeric values, width w with comma sep every three digits and period before decimal fraction d
  • like above but has $ before
  • like above but non-US, has period every 3 digits, comma before decimal
  • like above non-US, but has euro sign before
A

$w. writes standard char data, width w
w.d writes standard num data, width w
COMMAw.d writes num val with comma sep every 3 dig, period before decimal fraction
DOLLARw.d like COMMA but has $ before
COMMAXw.d - non-US - commas every 3 digits, period before fraction
EUROXw.d like COMMAX but with euro sign before

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

Formats: what happens to character values if don’t fit in specified width?

A

character values TRUNCATED if don’t fit in specified width

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

Formats: what happens to numeric values if don’t fit in specified width?

A

numeric values ROUNDED to fit;

commas, $ dropped if need be

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

How does SAS store dates?

A

SAS stores dates as # of days from Jan 1 1960 (=0)
Dates earlier than 1960 have negative value

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

How would these dates be displayed?
MMDDYY6. 0 =?
MMDDYY8. 0 =?
MMDDYY10. 0 =?
DDMMYY10. 365 =?

A

MMDDYY6. 0 = 010160
MMDDYY8. 0 = 01/01/60
MMDDYY10. 0 = 01/01/1960
DDMMYY10. 365 = 31/12/1960

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

How do you make a user-defined format? (steps)

What is format associated with?

A

2 steps to make user-defined format:

1) PROC FORMAT to create format
2) FORMAT variable(s) format in PROC PRINT to apply format to variable

Format created isn’t associated with particular variable, rather with values to display differently

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

PROC FORMAT syntax?

What keywords are used in step?

A

Proc Format syntax:

PROC FORMAT;
VALUE format-name value-or-range1 = ‘formated-value1’
value-or-range2 = ‘formated-value2’ ….
RUN;

Keywords: PROC, FORMAT, VALUE, RUN

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

PROC FORMAT format name rules:

character format name:
must start with?

numeric format name: must start with?
ending?
can only use?
can’t use?
what about period?

A

character format name:
must start w $ + letter or underscore

numeric format name:
must start with letter or underscore
ending: cannot end in number

can only use: letters, numbers, underscores

can’t use: SAS format names

what about period? doesn’t end with period in value statement (will specify period when refer to format name in format statement)

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

what can value-or-range be? (3)

A

value-or-range can be:

individual (‘AU’), (1)

range (‘B’-‘D’) (0-5000)

list (‘U’,’V’) (1,2,3)

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

value-or-range:

syntax requirements for character values? case?

numeric values?

range?

list?

A

value-or-range:

syntax requirements for character values:
must be in quotes,
must match case

numeric values:
do NOT use quotes

range:
hyphen separates values that define end points

list: commas separate values

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

How reference missing value in value-or-range set?

Example?

A

Use . (period) to reference missing value in value-or-range set.

proc format;
value
testvar1 0-<10=’less than 10’
10-20=’between 10 and 20’
.=’has missing value’
other=’not defined’;

run;

17
Q

how write formatted value?
quotes required?

length?

A

usually use quotes for formatted value, but not required

Length: formatted values can be ~32k char long

18
Q

what is keyword OTHER for?

A

Keyword OTHER = ‘whatever you want’

ex: ‘not specified’

  • will display this text if no other format works
  • otherwise will just display as seen in database
19
Q

PROC FORMAT, PROC PRINT using FORMAT

PROC FORMAT example (country, sport)

How many formats per value statement?

How many value statements per PROC FORMAT?

A

PROC FORMAT;
value $ctryfmt ‘AU’=’Australia’
‘US’=’United States’
OTHER=’miscoded’;
value $sports ‘FB’=’Football’
‘BK’=’Basketball’
‘BS’=’Baseball’’
RUN;

  • only one format per value statement
  • multiple value statements per PROC FORMAT
20
Q

PROC FORMAT, PROC PRINT using FORMAT

using FORMAT in PROC PRINT example

define format for salary, Birth_Date, Country
(use SAS formats, others previously defined)

A

PROC PRINT data=orion.sales label;
FORMAT salary dollar10.
Birth_Date Hire_Date MONYY7.
Country $ctryfmt.; (note period after t)
RUN;

21
Q

PROC FORMAT, PROC PRINT

using FORMAT & using range of values in PROC FORMAT

=> tiers example

A

PROC FORMAT;
value tiers 20000-49999 = ‘Tier1’
50000-99999 = ‘Tier2’
100000-250000 = ‘Tier3’
RUN;

22
Q

Notes about range of values:
are first, last values included?

how exclude from range?
first value?
last value?
both?

keywords for lowest, highest values?

character values - lowest possible value?
same for numeric?

A

values are inclusive
- includes first and last value

  • use “<” to EXCLUDE value from range
    “<-“ excludes first value
    “-<” excludes last value
    “<-<” excludes first and last value

use keywords “low” and “high” to specify lowest, highest value

for character values, missing = lowest possible value
NOT for numeric - does not include missing value

23
Q

When using format in statement, what do you need to be careful to include?

A

Don’t forget the period at the end of the format name!!!

No period => SAS thinks it is another variable name, not a format.