Differences between revisions 1 and 2
Revision 1 as of 2019-12-03 06:11:57
Size: 2237
Comment: Initial commit
Revision 2 as of 2019-12-06 02:25:13
Size: 2885
Comment:
Deletions are marked like this. Additions are marked like this.
Line 44: Line 44:
== Length Statement ==

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

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

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

data TEST2;
    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

These are appended to the string format:

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


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 TEST1;
    VAR="FOO";
    VAR="FOOBAR";
run;

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

data TEST2;
    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

These are appended to the string format:

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


CategoryRicottone

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