Date not extracted correctly..
I have run a sas file I have through the script and the two date columns I have come out as an integer.. I have run the same file through stat-transfer and the date columns come out as dates.. example: sas7bdat script produces 19363 while the ST program produces 1/5/2013... Could possibly be the way I'm using it? (I'm running it via Jython and it's called from a Grails app.. works great otherwise though!!!)
Comments (9)
-
reporter -
repo owner Do you have a sample file you could send me?
-
reporter I will see what I can do.. (I had to sign an NDA to see it.. so will see if I can make one).. for the record I figured out what the # is.. it's the number of years since 1/1/1960.. so for now on the Groovy side I'm calculating what the actual date is..
-
repo owner Strange, since that's what the code does...
-
repo owner By the way, have you tried running the standalone script with the –header option to see what the datestamp reports? Also, have you tried cloning the latest version and doing the same thing?
-
repo owner - changed status to resolved
I'm going to mark this as resolved since I added support for custom formatters in the latest version. To use, pass a dictionary mapping the format string to a callable that accepts the value as a single argument to the
formatters
kwarg in theSAS7BDAT
constructor. For example:f = SAS7BDAT('foo.sas7bdat', formatters={'CUSTOM_FORMAT': lambda x: x.title()})
In this example, when calling the
convertFile
method, any value with "CUSTOM_FORMAT" in the "Format" column will be converted to title case. You should easily be able to add support for your "MMDDYY10" column this way. -
I have a similar problem to @gpinkham (although the format I'm using is YYMMDDS). I just downloaded v1.0.3, and there is no formatters argument. Did you remove it? If so, please consider adding YYMMDDx (where x can be B, C, D, N, P, or S) to your list of DATE_FORMAT_STRINGS.
In [7]: ds = sas.SAS7BDAT("test.sas7bdat", formatters={'YYMMDDS': lambda x: x.Title()}) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-7-c61a87146bd8> in <module>() ----> 1 ds = sas.SAS7BDAT("test.sas7bdat", formatters={'YYMMDDS': lambda x: x.Title()}) TypeError: __init__() got an unexpected keyword argument 'formatters'
-
repo owner Hi John,
With the 1.0 rewrite, unfortunately the API did change a bit. In addition to adding compressed file support, we now no longer format the values that come back but rather return a string, float, time, datetime, or date object. I just updated the library to version 1.0.4 which adds support for additional format strings so in your case, it would work something like:
from sas7bdat import SAS7BDAT with SAS7BDAT('test.sas7bdat', extra_date_format_strings=['YYMMDDS']) as ds: for row in ds: print ds
Keep in mind that the columns with date format
YYMMDDS
will be returned asdatetime.date
objects so if you want to reformat them, you'll need to handle that (something likex.strftime('%y%m%d%s')
)Hope this helps
-
I'll update to 1.0.4 and check out the new feature.
Edit: new feature works as advertised. Thanks!
- Log in to comment
for the record the column defs in the sas7bdat file is:
start_d Num 8 MMDDYY10. stop_d Num 8 MMDDYY10