I have a data set with 6-digit numeric variables (leading blank for single dates) representing ddmmyy, (not dd/mm/yy) but cannot get them into edate format. The dates are duplicated as 2-digit variables dd, mm yy. There are also time variables in 4-digit format hhmm (not hh:mm). Changing the format from numeric to date doesn’t work (year changes from 89 to 82!) Is it possible to convert existing variables? I can’t find anything in the syntax ref manual to help with conversion or starting from scratch with DATA LIST. Can anyone help? TIA John F Hall |
John: You will need to parse the numeric data to create a date formatted
variable: *Untested COMPUTE yourdate = DATE.DMY( TRUNC(yournbr/1000) , TRUNC(yournbr –trunc(yournbr/1000)*1000) ), TRUNC(yournbr –trunc(yournbr/10)*10) ) ). Format yourdate (edate10). EXEC. Jim Marks Director of Market Research x 1616 From: SPSSX(r) Discussion
[mailto:[hidden email]] On Behalf Of John F Hall I have a data set with 6-digit numeric
variables (leading blank for single dates) representing ddmmyy, (not dd/mm/yy)
but cannot get them into edate format. The dates are duplicated as
2-digit variables dd, mm yy. There are also time variables in 4-digit
format hhmm (not hh:mm). Changing the format from numeric to date doesn’t
work (year changes from 89 to 82!) Is it possible to convert existing
variables? I can’t find anything in the syntax ref manual to help
with conversion or starting from scratch with DATA LIST. Can anyone help? TIA John F Hall |
In reply to this post by John F Hall
Eventually managed to sort this myself after checking out Jacqueline Collier’s book, “Using SPSS Syntax: A Beginner’s Guide” (Sage, 2010). She’s red-hot on date and time functions. Transform > Date and Time Wizard gave me the following syntax: * Date and Time Wizard: xx. COMPUTE xx=DATE.DMY(SQDate2D, SQDate2M, SQDate2Y). VARIABLE LABELS xx "Date completed Quaire 2". VARIABLE LEVEL xx (SCALE). FORMATS xx (EDATE8). VARIABLE WIDTH xx(8). EXECUTE. Gives me something to play with and see if it’s true about “Blue Monday”, respondent fatigue and all sorts of other things. John F Hall From: John F Hall [mailto:[hidden email]] I have a data set with 6-digit numeric variables (leading blank for single dates) representing ddmmyy, (not dd/mm/yy) but cannot get them into edate format. The dates are duplicated as 2-digit variables dd, mm yy. There are also time variables in 4-digit format hhmm (not hh:mm). Changing the format from numeric to date doesn’t work (year changes from 89 to 82!) Is it possible to convert existing variables? I can’t find anything in the syntax ref manual to help with conversion or starting from scratch with DATA LIST. Can anyone help? TIA John F Hall |
Administrator
|
In reply to this post by John F Hall
John,
I am surprised that after your decades of using basic SPSS you are unfamiliar with the DATE aggregation functions (eg DATE.MDY(mm,dd,yy(yy) ). The EDATE issue would be FORMAT issue. HTH, David
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 John F Hall
If the dates also exist as three separate
variables:
compute datevar=date.dmy(day, month, year) formats datevar (edate10). /*or whatever date display format you want. If the times always contain four digits: compute #hour=substr(timevar, 1, 2). compute #minute=substr(timevar,3). compute newtimevar=time.hms(#hour, #minute). formats newtimevar(time5) In the help, try searching for "date functions". From: John F Hall <[hidden email]> To: [hidden email] Date: 09/22/2011 11:40 AM Subject: How to read/convert 6-digit numeric as edate Sent by: "SPSSX(r) Discussion" <[hidden email]> I have a data set with 6-digit numeric variables (leading blank for single dates) representing ddmmyy, (not dd/mm/yy) but cannot get them into edate format. The dates are duplicated as 2-digit variables dd, mm yy. There are also time variables in 4-digit format hhmm (not hh:mm). Changing the format from numeric to date doesn’t work (year changes from 89 to 82!) Is it possible to convert existing variables? I can’t find anything in the syntax ref manual to help with conversion or starting from scratch with DATA LIST. Can anyone help? TIA John F Hall johnfhall@... www.surveyresearch.weebly.com |
In reply to this post by John F Hall
Full documentation of date aggregation
functions can be found here:
http://publib.boulder.ibm.com/infocenter/spssstat/v20r0m0/index.jsp?topic=%2Fcom.ibm.spss.statistics.help%2Fsyn_date_and_time_aggregation_functions.htm From: Rick Oliver/Chicago/IBM To: John F Hall <[hidden email]> Cc: [hidden email] Date: 09/22/2011 12:02 PM Subject: Re: How to read/convert 6-digit numeric as edate If the dates also exist as three separate variables: compute datevar=date.dmy(day, month, year) formats datevar (edate10). /*or whatever date display format you want. If the times always contain four digits: compute #hour=substr(timevar, 1, 2). compute #minute=substr(timevar,3). compute newtimevar=time.hms(#hour, #minute). formats newtimevar(time5) In the help, try searching for "date functions". From: John F Hall <[hidden email]> To: [hidden email] Date: 09/22/2011 11:40 AM Subject: How to read/convert 6-digit numeric as edate Sent by: "SPSSX(r) Discussion" <[hidden email]> I have a data set with 6-digit numeric variables (leading blank for single dates) representing ddmmyy, (not dd/mm/yy) but cannot get them into edate format. The dates are duplicated as 2-digit variables dd, mm yy. There are also time variables in 4-digit format hhmm (not hh:mm). Changing the format from numeric to date doesn’t work (year changes from 89 to 82!) Is it possible to convert existing variables? I can’t find anything in the syntax ref manual to help with conversion or starting from scratch with DATA LIST. Can anyone help? TIA John F Hall johnfhall@... www.surveyresearch.weebly.com |
Free forum by Nabble | Edit this page |