Another date conversion question

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Another date conversion question

FernandezLanier, Adriana (DCJS)

Good morning. I hit another date snag in my data set. There is a variable called admission date in the file but it’s in a numeric format and not a date function. For example, the date, Nov. 8, 2006, appears as 20061108 in the file. The month, day, and year have been extracted (2006,11,8). How can I convert the numeric format version into a date format or even use the month, day, year variable to compute a date variable.  Once I have this date I then can calculate time differences. Any suggestions would be greatly appreciated. Thanks, Adriana

 

 

 

 

 

P Please consider the environment before printing this e-mail.

 



This e-mail, including any attachments, may be confidential, privileged or otherwise legally protected. It is intended only for the addressee. If you received this e-mail in error or from someone who was not authorized to send it to you, do not disseminate, copy or otherwise use this e-mail or its attachments. Please notify the sender immediately by reply e-mail and delete the e-mail from your system.
Reply | Threaded
Open this post in threaded view
|

Re: Another date conversion question

aschoff
Hi, 

I think one option is to first convert your original numeric format (20061108) into a string format and the use the "Date and Time Wizard" from the menu to transform this string variable into a date variable. You just have to select the correct input and desired output format. With the resulting variable you should be able to make further date calculations.

Robinson





On 19.02.2010, at 14:28, FernandezLanier, Adriana (DCJS) wrote:

Good morning. I hit another date snag in my data set. There is a variable called admission date in the file but it’s in a numeric format and not a date function. For example, the date, Nov. 8, 2006, appears as 20061108 in the file. The month, day, and year have been extracted (2006,11,8). How can I convert the numeric format version into a date format or even use the month, day, year variable to compute a date variable.  Once I have this date I then can calculate time differences. Any suggestions would be greatly appreciated. Thanks, Adriana
 
 
 
 
 
P Please consider the environment before printing this e-mail.
 


This e-mail, including any attachments, may be confidential, privileged or otherwise legally protected. It is intended only for the addressee. If you received this e-mail in error or from someone who was not authorized to send it to you, do not disseminate, copy or otherwise use this e-mail or its attachments. Please notify the sender immediately by reply e-mail and delete the e-mail from your system.






Reply | Threaded
Open this post in threaded view
|

Re: Another date conversion question

Marta Garcia-Granero
In reply to this post by FernandezLanier, Adriana (DCJS)
FernandezLanier, Adriana (DCJS) wrote:

>
> Good morning. I hit another date snag in my data set. There is a
> variable called admission date in the file but it’s in a numeric
> format and not a date function. For example, the date, Nov. 8, 2006,
> appears as 20061108 in the file. The month, day, and year have been
> extracted (2006,11,8). How can I convert the numeric format version
> into a date format or even use the month, day, year variable to
> compute a date variable. Once I have this date I then can calculate
> time differences. Any suggestions would be greatly appreciated.
> Thanks, Adriana
>
Hi

If you don't want to transform your numeric variable into a string, you
can use this approach (provided that all your dates have 8 digits: 4 for
the year, 2 for the month and 2 for the day):

* Sample dataset *.
DATA LIST LIST/DatesN(F8).
BEGIN DATA
20061108
END DATA.

* Temporary extraction of the components *.
COMPUTE #Years = TRUNC(DatesN/10000) .
COMPUTE #Months=TRUNC(DatesN/100)-#Years*100.
COMPUTE #Days=DatesN-#Years*10000-#Months*100.

* Compute date *.
COMPUTE TrueDate = DATE.DMY(#Days, #Months, #Years).
VARIABLE LEVEL TrueDate (SCALE).
* I have selected yyyy-mm-dd as format, but there are other formats like
dd-mm-yyyy *.
FORMATS TrueDate (SDATE10).
VARIABLE WIDTH TrueDate(10).

* See result *.
LIST.

HTH,
Marta GG

--
For miscellaneous SPSS related statistical stuff, visit:
http://gjyp.nl/marta/

=====================
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