Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: converting SAS file to stata using stat transfer-date and time variables


From   Leny Mathew <lenymathewc@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: converting SAS file to stata using stat transfer-date and time variables
Date   Mon, 20 Dec 2010 16:04:44 -0500

Hi Bill,

Thank you for you comments, Sorry about the late reply, life got in the way!

The SAS file that I'm working with was created by someone else. I
don't have SAS on my system and work exclusively with stata. However,
the people who provided me the file have a system through which I can
access SAS on their server, look at the file, and download it. The
accompanying code book specified that the time variable was stored as
a SAS time variable with values 0-99999, formatted as HH:MM:SS. Since
I couldn't get the file to transfer properly into stata, I converted
into excel, that worked fine! I can save this as a .csv file and then
import it into stata. This would work, but that would be pain to do
this every time. When converting, I selected to use double in stat
transfer.
The values are between 0 and 1

contactlogtime
                                   the time of the contact
---------------------------------------------------------------------------------------------------------------------------------

                  type:  numeric (float)

                 range:  [.03483796,.97546852]        units:  1.000e-09
         unique values:  22094                    missing .:  4/32368

                  mean:   .577952
              std. dev:   .190205

           percentiles:        10%       25%       50%       75%       90%
                           .397106   .479514   .605961   .722454   .793056


It makes sense, 12 PM is 0.5, 15:00 is 0.625, 18:00 is 0.75 and so on,
but I'm at a loss to figure out why this happens.

Thanks,

Leny



**********************************************************************************************************************************************************************************




On Mon, Dec 20, 2010 at 12:09 PM, William Gould, StataCorp LP
<wgould@stata.com> wrote:
>> I'm trying to convert a SAS file (V 9.1) with date and time variables
>> (separate) into stata and I'm using stat transfer (version 8) for
>> this. During the conversion, the date variable comes across fine, but
>> all the time variable values are between 0 and 1. stat transfer reads
>> the SAS file without any problem, it looks fine in the viewer and it
>> converts into excel without any problem. I didn't have to format the
>> date variable within stata, so I'm assuming that I don't have to do
>> any formatting for the time variable either. Has anyone had this issue
>> before?
>
> This should be easy because SAS and Stata save times in similar ways.
> Stata stores times as microseconds since 01jan1960; SAS as seconds. Thus,
> the transormation is
>
>        . gen double stata_time = sas_time*1000
>        . format stata_time %tc
>
> Be sure that the original SAS time is recorded as a double.
>
> Leny wrote "all the time variable values are between 0 and 1". I'm assuming
> they are actually very large numbers and Leny didn't notice the e+## on
> the end.  If the numbers really are between 0 and 1, I don't think they
> are SAS time values.
>
> -- Bill
> wgould@stata.com
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index