Size: 1234
Comment: Initial commit
|
Size: 3485
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
= Datetime = | = SPSS Formats = SPSS supports numeric variables and strings, with conversion options and some automatic conversion functionality. There are several formats on top of numerics that impact visualization, not storage. |
Line 3: | Line 4: |
== A warning about data input == | <<TableOfContents>> ---- == Datetime == === A warning about data input === |
Line 20: | Line 29: |
== Datetime formats == | === Datetime formats === |
Line 36: | Line 45: |
=== Parse Timestamps === A macro for timestamp conversion, from `dd/mm/yyyy hh:mm` to SPSS `DATETIME20`: {{{ define !str2datetime (in=!tokens(1) / out=!cmdend) numeric !out (DATETIME20). compute !out = date.mdy( number(char.substr(!in,1,2), f2), number(char.substr(!in,4,2), f2), number(char.substr(!in,7,4), f4) ) + time.hms( number(char.substr(!in,12,2), f2), number(char.substr(!in,15,2), f2), 0 ) . !enddefine. !str2datetime in=mytimestampvar out=mydatetimevar. }}} === Create Timestamps === This is unfortunately long-winded. {{{ data list free / a. begin data. 1 end data. dataset name TIMESTAMP. execute. string tmp_date (A11) datetime (A20). compute tmp_date = $date. alter type tmp_date (date11). compute tmp_time = $time. * Built-in formats. compute datetime=string(tmp_date, ADATE10). execute. * Manual formats. compute datetime=concat( char.substr(string(xdate.year(tmp_date),N4),3,2), string(xdate.month(tmp_date),N2), string(xdate.mday(tmp_date),N2), "_", string(xdate.hour(tmp_time),N2), string(xdate.minute(tmp_time),N2), ). execute. do if $casenum=1. write outfile 'timestamp.sps' /1 "define !timestamp() " datetime " !enddefine.". end if. dataset close TIMESTAMP. execute. insert file='timestamp.sps'. execute. }}} ---- == Numerics == Formats only truncate the displayed value, or the value translated into data files. SPSS always retains data to original precision. Given 123.45... ||'''Format''' ||'''Using...''' ||'''Appears as...''' || ||Fw ||F8 ||123 || ||Fw.d ||F8.1 ||123.4 || ||Nw ||N8 ||00000123 || ||Nw.d ||N8.1 ||000123.4 || ---- == Strings == String variables are only formatted to a length. The format is specified as `AN` where `N` is the width. |
SPSS Formats
SPSS supports numeric variables and strings, with conversion options and some automatic conversion functionality. There are several formats on top of numerics that impact visualization, not storage.
Contents
Datetime
A warning about data input
SPSS tries to be clever about reading data.
Under the format TIME, all of these are read in as "01:02", even though the format is a minimum of 5-wide:
"1:2"
"01 2"
"01:02"
Under the format DATE, all of these are read in as "28-OCT-90":
"28-OCT-90"
"28/10/1990"
"28.OCT.90"
"28 October, 1990"
Datetime formats
Format |
Appears as... |
Note |
DATETIME20 |
dd-MMM-yyyy hh:mm:ss |
MMM is as JAN, not 001 |
DATETIME18 |
dd-MMM-yyyy hh:mm |
MMM is as JAN, not 001 |
DATE11 |
dd-MMM-yyyy |
MMM is as JAN, not 001 |
DATE7 |
dd-MMM-yy |
MMM is as JAN, not 001 |
TIME8 |
hh:mm:ss |
|
TIME5 |
hh:mm |
|
ADATE10 |
mm/dd/yyyy |
|
ADATE8 |
mm/dd/yy |
|
EDATE10 |
dd.mm.yyyy |
|
EDATE8 |
dd.mm.yy |
|
Parse Timestamps
A macro for timestamp conversion, from dd/mm/yyyy hh:mm to SPSS DATETIME20:
define !str2datetime (in=!tokens(1) / out=!cmdend) numeric !out (DATETIME20). compute !out = date.mdy( number(char.substr(!in,1,2), f2), number(char.substr(!in,4,2), f2), number(char.substr(!in,7,4), f4) ) + time.hms( number(char.substr(!in,12,2), f2), number(char.substr(!in,15,2), f2), 0 ) . !enddefine. !str2datetime in=mytimestampvar out=mydatetimevar.
Create Timestamps
This is unfortunately long-winded.
data list free / a. begin data. 1 end data. dataset name TIMESTAMP. execute. string tmp_date (A11) datetime (A20). compute tmp_date = $date. alter type tmp_date (date11). compute tmp_time = $time. * Built-in formats. compute datetime=string(tmp_date, ADATE10). execute. * Manual formats. compute datetime=concat( char.substr(string(xdate.year(tmp_date),N4),3,2), string(xdate.month(tmp_date),N2), string(xdate.mday(tmp_date),N2), "_", string(xdate.hour(tmp_time),N2), string(xdate.minute(tmp_time),N2), ). execute. do if $casenum=1. write outfile 'timestamp.sps' /1 "define !timestamp() " datetime " !enddefine.". end if. dataset close TIMESTAMP. execute. insert file='timestamp.sps'. execute.
Numerics
Formats only truncate the displayed value, or the value translated into data files. SPSS always retains data to original precision.
Given 123.45...
Format |
Using... |
Appears as... |
Fw |
F8 |
123 |
Fw.d |
F8.1 |
123.4 |
Nw |
N8 |
00000123 |
Nw.d |
N8.1 |
000123.4 |
Strings
String variables are only formatted to a length. The format is specified as AN where N is the width.