----- Original Message -----
From: "Werner Mueller" <[hidden email]> To: <[hidden email]> Sent: Tuesday, December 05, 2006 10:44 AM Subject: [Quarantine] Converting international long time-strings to valid SPSS 11 date-formats > Dear list, > > I am having trouble converting a string variable (A45) to a SPSS date > format. > It is longer as usual, because it has a leading weekday-name > AND I have different .sav files from different countries, > and each weekday-name and month-name is localized! > > So I have dutch strings > woensdag 29 november 2006 20:48:59 > woensdag 29 november 2006 20:54:54 > woensdag 29 november 2006 20:56:02 > woensdag 29 november 2006 20:58:48 > zondag 3 december 2006 11:51:14 > zondag 3 december 2006 12:19:40 > zondag 3 december 2006 12:31:26 > > and also spanish strings > lunes, 27 de noviembre de 2006 14:26:20 > Martes, 28 de Noviembre de 2006 02:30:58 a.m. > lunes, 27 de noviembre de 2006 14:38:55 > martes, 28 de noviembre de 2006 14:41:43 > martes, 28 de noviembre de 2006 15:13:18 > Martes, 28 de Noviembre de 2006 03:22:16 a.m. > lunes, 27 de noviembre de 2006 15:33:39 > martes, 28 de noviembre de 2006 15:31:47 > lunes, 27 de noviembre de 2006 15:49:17 > > and also french, italian, .... > and, some have the 24-hour format, some work with a.m./p.m. (as you can > see above). > > 1. I would like to convert them all to the same time format and > because I have 3 of those 45-Character String-Variables for each > resondent (time1, time2, time3), > 2. I would like to calculate differences between time1, time2, and time3. > Usually all three times belong to one day, and it would be OK, > if I loose the dayname and just calculate the differences in > hours/minutes. > > I searched in the last 20000 emails from this group and also > Mr.Levesque's homepage, > but I did not find any time-conversion-examples that dealed with those > long time-stamps > and the differrent country-languages + partial am/pm problems. > > I confess, I come undone with this problem! > > Any help would be much appreciated. > > Werner Mueller > (University of Duesseldorf, Germany) |
Shalom
Here is another way of doing what you need . it will run on spss 11.5 (needs the casetovars) . with a small adaptation it can run even on spss 6 . The advantage of this approach is using aggregation witch ensure that you will have all the data needed for the translation (recoding) . also it is relatively small. The program assume that all data have the same order (weekday day month year time am_pm) . DATA LIST FREE/ str(a60). BEGIN DATA zz1 woensdag 29 november 2006 20:48:59 zz2 woensdag 29 november 2006 20:54:54 zz3 woensdag 29 november 2006 20:56:02 zz4 woensdag 29 november 2006 20:58:48 zz5 zondag 3 december 2006 11:51:14 zz6 zondag 3 december 2006 12:19:40 zz7 zondag 3 december 2006 12:31:26 zz8 lunes, 27 de noviembre de 2006 14:26:20 zz9 Martes, 28 de Noviembre de 2006 02:30:58 a.m. zz10 lunes, 27 de noviembre de 2006 14:38:55 zz11 martes, 28 de noviembre de 2006 14:41:43 zz12 martes, 28 de noviembre de 2006 15:13:18 zz13 Martes, 28 de Noviembre de 2006 03:22:16 a.m. zz14 lunes, 27 de noviembre de 2006 15:33:39 zz15 martes, 28 de noviembre de 2006 15:31:47 zz16 lunes, 27 de noviembre de 2006 15:49:17 end data. compute seq=$casenum. sort cases by str . SAVE OUTFILE='date_data.sav' /COMPRESSED. aggregate outfile= * / break=str / n=n(str) . select if (substr(str,1,1) > '9') and (substr(str,1,2) < 'zz' ) . SAVE OUTFILE='date_hlp.sav' /COMPRESSED. *********************************************************** . * After you do the aggregate you should add the new(translate) values to the help table(data_hlp.sav) to get a table like this . * (datetype are 2= weekday 3=month 0=discard 1=am_pm ) . * I am adding the table as data here because there is no way to attach the created file . *********************************************************** . data list list /str(a20) n datetype dataval . BEGIN DATA a.m. 2 1 de 18 0 december 3 2 12 lunes 4 3 2 martes 3 3 3 Martes 2 3 3 november 4 2 11 noviembre 7 2 11 Noviembre 2 2 11 woensdag 4 3 4 zondag 3 3 1 end data. *match files file='date_data.sav' / table='date_hlp.sav' . match files file='date_data.sav' / table= * / by str/ drop=n . select if sysmis(datetype) or datetype gt 0 . sort cases by seq. numeric caseseq(f1) casenum(f8). string newstr(a20) . leave caseseq casenum newstr. if substr(str,1,2) eq 'zz' caseseq=0. if substr(str,1,2) eq 'zz' casenum=sum(casenum,1). compute caseseq=sum(caseseq,1) . compute caseseq=caseseq . compute casenum=casenum . compute newstr=str. if datetype eq 2 or datetype eq 3 newstr=strng(dataval,f4) . execute . execute . SORT CASES BY casenum caseseq . formats caseseq(f1). CASESTOVARS /ID = casenum /INDEX = caseseq /drop=str seq datetype dataval /GROUPBY = VARIABLE . rename vars (newstr.1 newstr.2 newstr.3 newstr.4 newstr.5 newstr.6 newstr.7 = idcode weekday day month year time am_pm ). compute spssdate=date.dmy(number(ltrim(tday),f2),number(ltrim(tmonth),f2),number(ltrim(tyear),f4)) . compute spsstime=TIME.HMS(number(substr(ltrim(ttime),1,2),f2) ,number(substr(ltrim(ttime),4,2),f2) ,number(substr(ltrim(ttime),7,2),f2) ). if index(lower(am_pm),'pm') spsstime=spsstime + (12*60*60) . formats spssdate(edate12) spsstime(time8). execute . Hillel Vardi IS wrote: > ----- Original Message ----- > From: "Werner Mueller" <[hidden email]> > To: <[hidden email]> > Sent: Tuesday, December 05, 2006 10:44 AM > Subject: [Quarantine] Converting international long time-strings to valid > SPSS 11 date-formats > > >> Dear list, >> >> I am having trouble converting a string variable (A45) to a SPSS date >> format. >> It is longer as usual, because it has a leading weekday-name >> AND I have different .sav files from different countries, >> and each weekday-name and month-name is localized! >> >> So I have dutch strings >> woensdag 29 november 2006 20:48:59 >> woensdag 29 november 2006 20:54:54 >> woensdag 29 november 2006 20:56:02 >> woensdag 29 november 2006 20:58:48 >> zondag 3 december 2006 11:51:14 >> zondag 3 december 2006 12:19:40 >> zondag 3 december 2006 12:31:26 >> >> and also spanish strings >> lunes, 27 de noviembre de 2006 14:26:20 >> Martes, 28 de Noviembre de 2006 02:30:58 a.m. >> lunes, 27 de noviembre de 2006 14:38:55 >> martes, 28 de noviembre de 2006 14:41:43 >> martes, 28 de noviembre de 2006 15:13:18 >> Martes, 28 de Noviembre de 2006 03:22:16 a.m. >> lunes, 27 de noviembre de 2006 15:33:39 >> martes, 28 de noviembre de 2006 15:31:47 >> lunes, 27 de noviembre de 2006 15:49:17 >> >> and also french, italian, .... >> and, some have the 24-hour format, some work with a.m./p.m. (as you can >> see above). >> >> 1. I would like to convert them all to the same time format and >> because I have 3 of those 45-Character String-Variables for each >> resondent (time1, time2, time3), >> 2. I would like to calculate differences between time1, time2, and >> time3. >> Usually all three times belong to one day, and it would be OK, >> if I loose the dayname and just calculate the differences in >> hours/minutes. >> >> I searched in the last 20000 emails from this group and also >> Mr.Levesque's homepage, >> but I did not find any time-conversion-examples that dealed with those >> long time-stamps >> and the differrent country-languages + partial am/pm problems. >> >> I confess, I come undone with this problem! >> >> Any help would be much appreciated. >> >> Werner Mueller >> (University of Duesseldorf, Germany) > |
Free forum by Nabble | Edit this page |