|
Hello again.
I have another doubt regarding dates in SPSS. I need to read a TXT file in which dates are in "yyyymmdd" format (for example, 20071224 for today). Which syntax do I need to use in SPSS in order to import that field correctly?? I tried GET DATA, with "SDATE8" format for the date field, but the result was an empty column. The point is that I don't know if SPSS accepts other date formats different from those described in the SPSS help file ("Date and Time Formats"). If not, I suppose that I should read the date field as a "character", and then "translate" the character column into date by means of syntax. Any (other) suggestion for this topic? Thnak you in advance for your help. -- Vicent ===================== 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 |
|
The SDATE format is YYYY/MM/DD. You do not have slashes in your number. As
you have surmised, you'll have to split the string variable up into its three parts and then rebuild the date variable: COMPUTE year=NUMBER(SUBSTR(mydate,1,4),f4). COMPUTE month=NUMBER(SUBSTR(mydate,5,2),f2). COMPUTE day=NUMBER(SUBSTR(mydate,7,2),f2). * Date and Time Wizard: newdatevar. COMPUTE newdatevar=DATE.DMY(day, month, year). VARIABLE LABEL newdatevar "". VARIABLE LEVEL newdatevar (SCALE). FORMATS newdatevar (SDATE10). VARIABLE WIDTH newdatevar(10). -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Vicent Giner Bosch Sent: Monday, December 24, 2007 6:55 AM To: [hidden email] Subject: Reading dates in "yyyymmdd" format Hello again. I have another doubt regarding dates in SPSS. I need to read a TXT file in which dates are in "yyyymmdd" format (for example, 20071224 for today). Which syntax do I need to use in SPSS in order to import that field correctly?? I tried GET DATA, with "SDATE8" format for the date field, but the result was an empty column. The point is that I don't know if SPSS accepts other date formats different from those described in the SPSS help file ("Date and Time Formats"). If not, I suppose that I should read the date field as a "character", and then "translate" the character column into date by means of syntax. Any (other) suggestion for this topic? Thnak you in advance for your help. -- Vicent ===================== 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 |
|
Alternatively:
compute #day=mod(datevar,100). compute #month=trunc(mod(datevar,10000)/100). compute #year=trunc(datevar/10000). compute newdate=date.dmy(#day, #month, #year). formats newdate (date11). ________________________________ From: SPSSX(r) Discussion on behalf of ViAnn Beadle Sent: Mon 12/24/2007 8:53 AM To: [hidden email] Subject: Re: Reading dates in "yyyymmdd" format The SDATE format is YYYY/MM/DD. You do not have slashes in your number. As you have surmised, you'll have to split the string variable up into its three parts and then rebuild the date variable: COMPUTE year=NUMBER(SUBSTR(mydate,1,4),f4). COMPUTE month=NUMBER(SUBSTR(mydate,5,2),f2). COMPUTE day=NUMBER(SUBSTR(mydate,7,2),f2). * Date and Time Wizard: newdatevar. COMPUTE newdatevar=DATE.DMY(day, month, year). VARIABLE LABEL newdatevar "". VARIABLE LEVEL newdatevar (SCALE). FORMATS newdatevar (SDATE10). VARIABLE WIDTH newdatevar(10). -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Vicent Giner Bosch Sent: Monday, December 24, 2007 6:55 AM To: [hidden email] Subject: Reading dates in "yyyymmdd" format Hello again. I have another doubt regarding dates in SPSS. I need to read a TXT file in which dates are in "yyyymmdd" format (for example, 20071224 for today). Which syntax do I need to use in SPSS in order to import that field correctly?? I tried GET DATA, with "SDATE8" format for the date field, but the result was an empty column. The point is that I don't know if SPSS accepts other date formats different from those described in the SPSS help file ("Date and Time Formats"). If not, I suppose that I should read the date field as a "character", and then "translate" the character column into date by means of syntax. Any (other) suggestion for this topic? Thnak you in advance for your help. -- Vicent ===================== 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 ====================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 Vicent Giner-Bosch
The Date/Time wizard will build syntax for you for some formats that are not built in directly to SPSS, including the one you ask about.
Assuming that you have read the date as a string, the wizard would generate the following syntax to convert it. (I used adate10 for the output format, but you can pick whatever you want. I didn't specify a variable label.) COMPUTE newdate=date.dmy(number(substr(ltrim(adate),7,2),f2.0), number(substr(ltrim(adate),5,2),f2.0), number(substr(ltrim(adate),1,4),f4.0)). VARIABLE LABEL newdate "". VARIABLE LEVEL newdate (SCALE). FORMATS newdate (ADATE10). VARIABLE WIDTH newdate(10). HTH, Jon Peck -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Vicent Giner Bosch Sent: Monday, December 24, 2007 6:55 AM To: [hidden email] Subject: [SPSSX-L] Reading dates in "yyyymmdd" format Hello again. I have another doubt regarding dates in SPSS. I need to read a TXT file in which dates are in "yyyymmdd" format (for example, 20071224 for today). Which syntax do I need to use in SPSS in order to import that field correctly?? I tried GET DATA, with "SDATE8" format for the date field, but the result was an empty column. The point is that I don't know if SPSS accepts other date formats different from those described in the SPSS help file ("Date and Time Formats"). If not, I suppose that I should read the date field as a "character", and then "translate" the character column into date by means of syntax. Any (other) suggestion for this topic? Thnak you in advance for your help. -- Vicent ===================== 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 |
| Free forum by Nabble | Edit this page |
