Dear All I would like to have a date
variable (formatted as dd.mm.yyyy, European date) printed in a table in the
same format. However, if a month (mm) is
smaller than 10 only one (m) is printed (see example below). I know, I easily could
translate the date into a string, but then I could not sort by date anymore. Does someone have a solution
for this. I am using SPSS 19.01 TIA, Christian data list list / Pat(F8.0)
ADM_Nr(A3) Date(EDATe10) Pos(f8.0) . begin data. 1 A07 02.04.2009 1 1 A01 21.02.2010 1 1 A07 31.12.2010 1 1 A06 30.11.2010 2 1 A07 04.09.2010 2 1 A02 06.10.2010 2 end data. Var LAbel Date "
". Val LAbel PAt 1 "
". Sort Cases by Date. CTABLES /FORMAT EMPTY = "
" MISSING='.' /SMISSING VARIABLE /VLABELS VARIABLES= Adm_Nr
Date DISPLAY=DEFAULT /TABLE Pat [c]
[Count " " F8.0] + (Adm_Nr >
Date [c] [COUNT " " F8.0]) /SLABELS POSITION=ROW /CATEGORIES VARIABLES=
Adm_Nr KEY=VALUE EMPTY=EXCLUDE /CATEGORIES VARIABLES=
Date ORDER=D KEY=VALUE EMPTY=Exclude. ********************************** |
I will be out of the office until Monday, April 25. If you need immediate assistance, please call 812-856-5824. I will respond to your e-mail
as soon as possible. Thank you,
Shimon Sarraf
Center for Postsecondary Research Indiana University at Bloomington |
Administrator
|
In reply to this post by la volta statistics
Hi Christian. If you had two versions of the date, a true date variable and a string, could you not use the date variable for sorting and the string for displaying?
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
Thanks Bruce
I tried that, but if you have a further nesting (and more data), this will not work. I expanded the example to show that, although I do not understand why this should not work. Look at the date 04.12.2009 for example. Both examples are included, the one with the string version and the one with the date version. So long, Christian data list list / Pat(F8.0) Center(A10) ADM_Nr(A3) Date(EDATe10) Pos(f8.0) . begin data. 1 xx1 A07 02.04.2009 1 1 xx1 A01 21.02.2010 1 1 xx1 A01 01.02.2010 2 1 xx1 A01 03.03.2011 2 1 xx1 A01 04.12.2009 2 1 xx1 A07 31.12.2011 1 1 xx1 A06 30.11.2010 2 1 xx4 A07 04.09.2010 2 1 xx4 A02 06.10.2013 2 1 xx4 A02 01.02.2010 2 1 xx1 A02 03.03.2011 2 1 xx1 A02 04.12.2009 2 1 xx4 A07 04.09.2010 2 1 xx4 A02 02.10.2013 2 1 xx4 A02 02.02.2010 2 1 xx4 A07 02.09.2010 2 1 xx4 A02 02.10.2013 2 1 xx4 A02 02.02.2010 2 1 xx4 A07 02.04.2009 1 1 xx4 A01 21.02.2010 1 1 xx4 A01 01.02.2010 2 1 xx4 A01 03.03.2011 2 1 xx4 A01 04.12.2009 2 1 xx4 A07 31.12.2011 1 1 xx4 A06 30.11.2010 2 1 xx1 A07 04.09.2010 2 1 xx1 A02 06.10.2013 2 1 xx1 A02 01.02.2010 2 1 xx4 A02 03.03.2011 2 1 xx4 A02 04.12.2009 2 1 xx1 A07 04.09.2010 2 1 xx1 A02 02.10.2013 2 1 xx1 A02 02.02.2010 2 1 xx1 A07 02.09.2010 2 1 xx1 A02 02.10.2013 2 1 xx1 A02 02.02.2010 2 end data. Var LAbel Date " ". Val LAbel PAt 1 " ". Var label Center "Center". Var label Adm_Nr "ADM". Sort Cases by Adm_Nr Center Date (A). String strDate_RegisterPat (A10). Compute strDate_RegisterPat = string(date, edate10). VARIABLE LABELS strDate_RegisterPat " ". CTABLES /FORMAT EMPTY = " " MISSING='.' /SMISSING VARIABLE /VLABELS VARIABLES= Adm_Nr Date DISPLAY=DEFAULT /TABLE Pat [c] [Count " " F8.0] + (Adm_Nr > Center > Date[c] [COUNT " " F8.0]) /SLABELS POSITION=ROW /CATEGORIES VARIABLES= Adm_Nr Center KEY=VALUE EMPTY=EXCLUDE /CATEGORIES VARIABLES= Date KEY=VALUE EMPTY=Exclude. Sort Cases by Adm_Nr Center Date (A). CTABLES /FORMAT EMPTY = " " MISSING='.' /SMISSING VARIABLE /VLABELS VARIABLES= Adm_Nr strDate_RegisterPate DISPLAY=DEFAULT /TABLE Pat [c] [Count " " F8.0] + (Adm_Nr > Center > strDate_RegisterPat [c] [COUNT " " F8.0]) /SLABELS POSITION=ROW /CATEGORIES VARIABLES= Adm_Nr Center KEY=VALUE EMPTY=EXCLUDE /CATEGORIES VARIABLES= strDate_RegisterPat KEY=VALUE EMPTY=Exclude. -----Ursprüngliche Nachricht----- Von: SPSSX(r) Discussion [mailto:[hidden email]] Im Auftrag von Bruce Weaver Gesendet: Montag, 18. April 2011 16:18 An: [hidden email] Betreff: Re: Date formate dd,mm,yyyy in tables Hi Christian. If you had two versions of the date, a true date variable and a string, could you not use the date variable for sorting and the string for displaying? la volta statistics wrote: > > Dear All > > I would like to have a date variable (formatted as dd.mm.yyyy, European > date) printed in a table in the same format. > > However, if a month (mm) is smaller than 10 only one (m) is printed (see > example below). > > I know, I easily could translate the date into a string, but then I could > not sort by date anymore. > > Does someone have a solution for this. I am using SPSS 19.01 > > TIA, Christian > > > > data list list / Pat(F8.0) ADM_Nr(A3) Date(EDATe10) Pos(f8.0) . > > begin data. > > 1 A07 02.04.2009 1 > > 1 A01 21.02.2010 1 > > 1 A07 31.12.2010 1 > > 1 A06 30.11.2010 2 > > 1 A07 04.09.2010 2 > > 1 A02 06.10.2010 2 > > end data. > > > > Var LAbel Date " ". > > Val LAbel PAt 1 " ". > > Sort Cases by Date. > > > > CTABLES > > /FORMAT EMPTY = " " MISSING='.' > > /SMISSING VARIABLE > > /VLABELS VARIABLES= Adm_Nr Date DISPLAY=DEFAULT > > /TABLE Pat [c] [Count " " F8.0] + > > (Adm_Nr > Date [c] [COUNT " " F8.0]) > > /SLABELS POSITION=ROW > > /CATEGORIES VARIABLES= Adm_Nr KEY=VALUE EMPTY=EXCLUDE > > /CATEGORIES VARIABLES= Date ORDER=D KEY=VALUE EMPTY=Exclude. > > ********************************** > la volta statistics > Christian Schmidhauser, Dr.phil.II > Weinbergstrasse 108 > CH-8006 Zürich > Tel: +41 (043) 233 98 01 > Fax: +41 (043) 233 98 02 > email: <mailto:[hidden email]> > mailto:[hidden email] > Web: <http://www.lavolta.ch/> www.lavolta.ch > ----- -- Bruce Weaver [hidden email] http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." NOTE: My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Date-formate-dd-mm-yyyy-in-tab les-tp4310840p4310865.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
In reply to this post by la volta statistics
Here is a way to restore the 0 in those
values using MODIFY TABLES. (It specifies level = -2, because there
is actually an empty final column in the row labels in this table.)
SPSSINC MODIFY TABLES subtype="Custom Table" SELECT="<<ALL>>" DIMENSION= ROWS LEVEL = -2 PROCESS = PRECEDING /STYLES APPLYTO=LABELS CUSTOMFUNCTION="customstylefunctions.modifyDateFormat". Here is the custom script, which you can add to customstylefunctions.py or put in another module and adjust the syntax accordingly. import re def modifyDateFormat(obj, i, j, numrows, numcols, section, more, custom): """change date formats of dates that have only one digit in the second field""" value = obj.GetValueAt(i,j) z=re.sub(r"""\.(\d)\.""", r".0\1.", value) if value != z: obj.SetValueAt(i,j, z) Jon Peck Senior Software Engineer, IBM [hidden email] 312-651-3435 From: la volta statistics <[hidden email]> To: [hidden email] Date: 04/18/2011 08:10 AM Subject: [SPSSX-L] Date formate dd,mm,yyyy in tables Sent by: "SPSSX(r) Discussion" <[hidden email]> Dear All I would like to have a date variable (formatted as dd.mm.yyyy, European date) printed in a table in the same format. However, if a month (mm) is smaller than 10 only one (m) is printed (see example below). I know, I easily could translate the date into a string, but then I could not sort by date anymore. Does someone have a solution for this. I am using SPSS 19.01 TIA, Christian data list list / Pat(F8.0) ADM_Nr(A3) Date(EDATe10) Pos(f8.0) . begin data. 1 A07 02.04.2009 1 1 A01 21.02.2010 1 1 A07 31.12.2010 1 1 A06 30.11.2010 2 1 A07 04.09.2010 2 1 A02 06.10.2010 2 end data. Var LAbel Date " ". Val LAbel PAt 1 " ". Sort Cases by Date. CTABLES /FORMAT EMPTY = " " MISSING='.' /SMISSING VARIABLE /VLABELS VARIABLES= Adm_Nr Date DISPLAY=DEFAULT /TABLE Pat [c] [Count " " F8.0] + (Adm_Nr > Date [c] [COUNT " " F8.0]) /SLABELS POSITION=ROW /CATEGORIES VARIABLES= Adm_Nr KEY=VALUE EMPTY=EXCLUDE /CATEGORIES VARIABLES= Date ORDER=D KEY=VALUE EMPTY=Exclude. ********************************** la volta statistics Christian Schmidhauser, Dr.phil.II Weinbergstrasse 108 CH-8006 Zürich Tel: +41 (043) 233 98 01 Fax: +41 (043) 233 98 02 email: mailto:schmidhauser@... Web: www.lavolta.ch |
Thanks Jon I found a faster
solution by doing an auto recode of the date variable (see Solution 2 below). I still find it
intriguing that the solution 3, in which I use the date as a string variable but
sort the data by the date variable, does some kind of self sorting, despite no
sort command is given in the CTABLES code. I would have expected the table to
show the same sorting as in the data set. Christian data list list /
Pat(F8.0) Center(A10) ADM_Nr(A3) Date(EDATe10) Pos(f8.0) . begin data. 1 xx1 A07
02.04.2009 1 1 xx1 A01
21.02.2010 1 1 xx1 A01
01.02.2010 2 1 xx1 A01
03.03.2011 2 1 xx1 A01
04.12.2009 2 1 xx1 A07
31.12.2011 1 1 xx1 A06
30.11.2010 2 1 xx4 A07
04.09.2010 2 1 xx4 A02
06.10.2013 2 1 xx4 A02
01.02.2010 2 1 xx1 A02
03.03.2011 2 1 xx1 A02
04.12.2009 2 1 xx4 A07
04.09.2010 2 1 xx4 A02
02.10.2013 2 1 xx4 A02
02.02.2010 2 1 xx4 A07
02.09.2010 2 1 xx4 A02
02.10.2013 2 1 xx4 A02
02.02.2010 2 1 xx4 A07
02.04.2009 1 1 xx4 A01
21.02.2010 1 1 xx4 A01
01.02.2010 2 1 xx4 A01
03.03.2011 2 1 xx4 A01
04.12.2009 2 1 xx4 A07
31.12.2011 1 1 xx4 A06
30.11.2010 2 1 xx1 A07
04.09.2010 2 1 xx1 A02
06.10.2013 2 1 xx1 A02
01.02.2010 2 1 xx4 A02
03.03.2011 2 1 xx4 A02
04.12.2009 2 1 xx1 A07
04.09.2010 2 1 xx1 A02
02.10.2013 2 1 xx1 A02
02.02.2010 2 1 xx1 A07
02.09.2010 2 1 xx1 A02
02.10.2013 2 1 xx1 A02
02.02.2010 2 end data. Var LAbel Date
" ". Val LAbel PAt 1
" ". Var label Var label Adm_Nr
"ADM". Sort Cases by
Date. Sort Cases by
Adm_Nr Center Date (A). AUTORECODE
VARIABLES=Date /INTO Date_Sort /PRINT. String
strDate_RegisterPat (A10). Compute
strDate_RegisterPat = string(date, edate10). VARIABLE LABELS
strDate_RegisterPat " ". * Solution 1, no
dd.mm.yyyy format. CTABLES /FORMAT EMPTY =
" " MISSING='.' /SMISSING
VARIABLE /VLABELS
VARIABLES= Adm_Nr Date DISPLAY=DEFAULT /TABLE
Pat [c] [Count " " F8.0] + (Adm_Nr
> Center > Date[c] [COUNT " " F8.0]) /SLABELS
POSITION=ROW /CATEGORIES
VARIABLES= Adm_Nr Center Date Order = A KEY=VALUE EMPTY=EXCLUDE. * solution 2,
correct dd.mm.yyyy format after auto-recoding the date variable. CTABLES /FORMAT EMPTY =
" " MISSING='.' /SMISSING
VARIABLE /VLABELS
VARIABLES= Adm_Nr Date_Sort DISPLAY=DEFAULT /TABLE
Pat [c] [Count " " F8.0] + (Adm_Nr
> Center > Date_Sort[c] [COUNT " " F8.0]) /SLABELS
POSITION=ROW /CATEGORIES
VARIABLES= Adm_Nr Center Date_sort Order = A KEY=VALUE EMPTY=EXCLUDE. Sort Cases by Adm_Nr
Center Date (A). * solution 3, not
correct sorting, despite no ORDER command is NOT given. CTABLES /FORMAT EMPTY =
" " MISSING='.' /SMISSING
VARIABLE /VLABELS
VARIABLES= Adm_Nr strDate_RegisterPat DISPLAY=DEFAULT /TABLE
Pat [c] [Count " " F8.0] + (Adm_Nr
> Center > strDate_RegisterPat [c] [COUNT " " F8.0]) /SLABELS
POSITION=ROW /CATEGORIES
VARIABLES= Adm_Nr Center KEY=VALUE EMPTY=EXCLUDE /CATEGORIES
VARIABLES= strDate_RegisterPat KEY=VALUE EMPTY=Exclude. Von: SPSSX(r) Discussion
[mailto:[hidden email]] Im Auftrag
von Jon K Peck Here is a way to restore the 0 in those values using
MODIFY TABLES. (It specifies level = -2, because there is actually an
empty final column in the row labels in this table.)
|
Administrator
|
Very nice, Christian. Thanks for sharing your solution.
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
Free forum by Nabble | Edit this page |