Differences between revisions 1 and 9 (spanning 8 versions)
Revision 1 as of 2019-12-03 06:11:57
Size: 2237
Comment: Initial commit
Revision 9 as of 2020-02-10 14:37:00
Size: 3075
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
= Datetime = = SAS Formats =

SAS supports numeric variables and strings, with conversion options. There are many (i.e. hundreds) of formats on top of numerics that impact visualization, not storage.

<<TableOfContents>>

----



== Datetime ==
Line 5: Line 15:
||'''Format''' ||'''Appears as...''' ||'''Note''' || ||'''Format''' ||'''Appears as...'''   ||'''Note''' ||
Line 21: Line 31:
----
Line 23: Line 34:
= Numerics =
=
= Numerics ==
Line 36: Line 48:
----
Line 38: Line 51:
= Strings =
=
= Strings ==
Line 44: Line 58:
=== Length Statement ===

Often, it is important to specify a string's length before creating it. Observe:

{{{
data _NULL_;
    VAR="FOO";
    VAR="FOOBAR";
run;

/* variable VAR is 3-wide and contains "FOO" */

data _NULL_;
    length VAR $60;
    VAR="FOO";
    VAR="FOOBAR";
run;

/* variable VAR is 60-wide and contains "FOOBAR" */
}}}



=== put Formats ===

The `put` function accepts additional formatting details:

 * `-L` left aligns the value
 * `-C` centers the value
 * `-R` right aligns the value

{{{
VAR2 = put(VAR1, $60. -R);
}}}


SAS Formats

SAS supports numeric variables and strings, with conversion options. There are many (i.e. hundreds) of formats on top of numerics that impact visualization, not storage.


Datetime

SAS prefers the DATE9 format--date constants are declared as "ddMMMyyyy"d. However there is a plethora of formats available.

Format

Appears as...

Note

DATETIME20

dd-MMM-yyyy:hh:mm:ss

MMM is as JAN, not 001

DATETIME18

ddMMMyyyy:hh:mm:ss

MMM is as JAN, not 001

DATETIME16

ddMMMyy:hh:mm:ss

MMM is as JAN, not 001

DATE11

dd-MMM-yyyy

MMM is as JAN, not 001

DATE9

ddMMMyyyy

MMM is as JAN, not 001

DATE7

ddMMMyy

MMM is as JAN, not 001

TIME8

hh:mm:ss

TIME5

hh:mm

MMDDYY10

mm/dd/yyyy

MMDDYY8

mm/dd/yy

DDMMYY10

dd/mm/yyyy

DDMMYY8

dd/mm/yy

MONYY7

MMMyyyy

MMM is as JAN, not 001

MONNAME

M

M is as January


Numerics

Given 12345.67...

Format

Using...

Appears as...

Note

w.

5.

12346

Round to nearest integer

w.d

5.1

12345.7

Round to nearest decimal at lowest precision

COMMAw.d

COMMA6.1

12,345.7

COMMAw.d

COMMA5.1

12345.7

Insufficient width for comma

DOLLARw.d

DOLLAR10.2

$12,345.67

EUROw.d

DOLLAR10.2

€12.345,67

European-style decimal and commas

Zw.d

Z8.

00012346


Strings

String variables are only formatted to a length. The format is specified as $N where N is the width.

Length Statement

Often, it is important to specify a string's length before creating it. Observe:

data _NULL_;
    VAR="FOO";
    VAR="FOOBAR";
run;

/* variable VAR is 3-wide and contains "FOO" */

data _NULL_;
    length VAR $60;
    VAR="FOO";
    VAR="FOOBAR";
run;

/* variable VAR is 60-wide and contains "FOOBAR" */

put Formats

The put function accepts additional formatting details:

  • -L left aligns the value

  • -C centers the value

  • -R right aligns the value

VAR2 = put(VAR1, $60. -R);


CategoryRicottone

SASFormats (last edited 2020-05-22 19:58:15 by DominicRicottone)