This is another of those 'Is
there a newer way questions?".
Since SPSS does not have an SDATE6 data input format, for more years than I can remember I have converted 6 digit dates (sortable dates in some parlance) to an SPSS date this way. do if indate ne 0. compute #temp = string(indate, n6). compute #yy = number(substr(#temp,1,2),n2). compute #mm = number(substr(#temp,3,2),n2). compute #dd = number(substr(#temp,5,2),n2). compute outdate = date.mdy(#mm, #dd, #yy). ELSE. compute outdate =86400. end if. Is there a newer way to do this? -- Art Kendall Social Research Consultants
Art Kendall
Social Research Consultants |
Well, not newer and maybe not any better,
but different:
data list free /sdate6. begin data 130504 101112 10101 end data. compute newdate=date.dmy(mod(sdate6,10), trunc(mod(sdate6,10000)/100), trunc(sdate6/10000)). formats newdate (adate10). list. Rick Oliver Senior Information Developer IBM Business Analytics (SPSS) E-mail: [hidden email] From: Art Kendall <[hidden email]> To: [hidden email], Date: 05/03/2013 03:48 PM Subject: 6 character number to SPSS date. Sent by: "SPSSX(r) Discussion" <[hidden email]> This is another of those 'Is there a newer way questions?". Since SPSS does not have an SDATE6 data input format, for more years than I can remember I have converted 6 digit dates (sortable dates in some parlance) to an SPSS date this way. do if indate ne 0. compute #temp = string(indate, n6). compute #yy = number(substr(#temp,1,2),n2). compute #mm = number(substr(#temp,3,2),n2). compute #dd = number(substr(#temp,5,2),n2). compute outdate = date.mdy(#mm, #dd, #yy). ELSE. compute outdate =86400. end if. Is there a newer way to do this? -- Art Kendall Social Research Consultants Art Kendall View this message in context: 6 character number to SPSS date. Sent from the SPSSX Discussion mailing list archive at Nabble.com. |
Administrator
|
In reply to this post by Art Kendall
Not exactly 'newer' maybe a bit more direct ;-)
DATA LIST / indate (N6) . BEGIN DATA 100230 130503 000000 END DATA. COMPUTE outdate=86400 . IF (indate NE 0) outdate=DATE.MDY(TRUNC(MOD(indate,1000)/100),MOD(indate,100), TRUNC(indate/10000)). FORMATS outdate (sdate). LIST. ------------------------------------- indate outdate 100230 2010/03/02 130503 2013/05/03 0 1582/10/15 Number of cases read: 3 Number of cases listed: 3
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
In reply to this post by Art Kendall
Sure.
data list fixed/sdate6(a6). begin data. 201231 130503 end data. dataset name dates. spssinc trans result=spssdate /formula 'extendedTransforms.strtodatetime(sdate6, "%y%m%d")'. For this example, the newer way offers no advantage, but it illustrates the ability to deal with just about any date format that might not be built in to SPSS without having to write any logic. You just have to define the pattern. The pattern language supports 23 components of date specifications. Details are in the extendedTransforms module available on the SPSS Community site. Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] phone: 720-342-5621 From: Art Kendall <[hidden email]> To: [hidden email], Date: 05/03/2013 02:49 PM Subject: [SPSSX-L] 6 character number to SPSS date. Sent by: "SPSSX(r) Discussion" <[hidden email]> This is another of those 'Is there a newer way questions?". Since SPSS does not have an SDATE6 data input format, for more years than I can remember I have converted 6 digit dates (sortable dates in some parlance) to an SPSS date this way. do if indate ne 0. compute #temp = string(indate, n6). compute #yy = number(substr(#temp,1,2),n2). compute #mm = number(substr(#temp,3,2),n2). compute #dd = number(substr(#temp,5,2),n2). compute outdate = date.mdy(#mm, #dd, #yy). ELSE. compute outdate =86400. end if. Is there a newer way to do this? -- Art Kendall Social Research Consultants Art Kendall View this message in context: 6 character number to SPSS date. Sent from the SPSSX Discussion mailing list archive at Nabble.com. |
Administrator
|
In reply to this post by Art Kendall
Hi Art. I think that new-fangled methods for dealing with dates would be found via the Date & Time Wizard (in the Transform menu). Here's what it produced for me just now. Note that I had to compute a string version of the input date variable (indatestr) before it would work via the D&T Wizard -- the option for extracting date info from a string is grayed out when there's no string variable!
new file. dataset close all. data list list / indate (n6). begin data 020503 130503 end data. string indatestr (a6). compute indatestr = string(indate,n6). * Date and Time Wizard: NewDate. COMPUTE outdate = date.dmy(number(substr(ltrim(indatestr),5,2),f2.0), number(substr(ltrim(indatestr),3,2),f2.0), number(substr(ltrim(indatestr),1,2),f2.0)). VARIABLE LEVEL outdate (SCALE). FORMATS outdate (DATE11). VARIABLE WIDTH outdate(11). EXECUTE. This is essentially the same as your method, but your syntax is neater--and it has the ELSE clause!
--
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/). |
Administrator
|
I guess those 'wizards' aren't the sharpest tools in the shed ;-)
--
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
Hello. I will be out of the office until Monday, May 13. I will do my best to respond to you upon my return.
Stephanie L. Marhefka, Ph.D. |
In reply to this post by David Marso
In the "good old days" of cards and card-images, (see [Traffic] thread) dates were punched as 3 pairs of 2 digits. Dozens of classic surveys in archives have interview dates entered like this, regardless of yymmdd, ddmmyy or mmddyy sequence. They can be read partially or in full (or both) using fixed format, and can be checked for evidence of “Blue Monday” etc. Incidentally, a great deal of early work on surveys was restricted to 2 x 2 tables because of the hassle of reloading cards from each bin after the first sort back into the card-sorters for second or subsequent sorts. Calculations for percentages and statistical tests were presumably done by hand or on a mechanical counting machine. John F Hall (Mr) [Retired academic survey researcher] Email: [hidden email] Website: www.surveyresearch.weebly.com Start page: www.surveyresearch.weebly.com/spss-without-tears.html -----Original Message----- I guess those 'wizards' aren't the sharpest tools in the shed ;-) -- Bruce Weaver wrote > Hi Art. I think that new-fangled methods for dealing with dates would > be found via the Date & Time Wizard (in the Transform menu). Here's > what it produced for me just now. Note that I had to compute a string > version of the input date variable (indatestr) before it would work > via the D&T Wizard -- the option for extracting date info from a > string is grayed out when there's no string variable! > > > new file. > dataset close all. > data list list / indate (n6). > begin data > 020503 > 130503 > end data. > > string indatestr (a6). > compute indatestr = string(indate,n6). > > * Date and Time Wizard: NewDate. > COMPUTE outdate = > date.dmy(number(substr(ltrim(indatestr),5,2),f2.0), > number(substr(ltrim(indatestr),3,2),f2.0), > number(substr(ltrim(indatestr),1,2),f2.0)). > VARIABLE LEVEL outdate (SCALE). > FORMATS outdate (DATE11). > VARIABLE WIDTH outdate(11). > EXECUTE. > > > This is essentially the same as your method, but your syntax is > neater--and it has the ELSE clause! > > > Art Kendall wrote >> This is another of those 'Is >> there a newer way questions?". >> Since SPSS does not >> have an SDATE6 data input format, for more years than I >> can remember I have converted 6 >> digit dates (sortable dates in some parlance) to an SPSS date this >> way. >> do if indate ne 0. >> compute #temp = string(indate, n6). >> compute #yy = number(substr(#temp,1,2),n2). >> compute #mm = number(substr(#temp,3,2),n2). >> compute #dd = number(substr(#temp,5,2),n2). >> compute outdate = date.mdy(#mm, #dd, #yy). >> ELSE. >> compute outdate =86400. >> end if. >> >> Is there a newer way to do this? >> -- >> Art Kendall >> Social Research Consultants ----- Please reply to the list and not to my personal email. Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/6-character-number-to-SPSS-date-tp5719933p5719938.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 |
Free forum by Nabble | Edit this page |