I've got a temporary work table with a date variable source_datetime in SAS DIS. This variable is in the DATETIME22.6 format.
I have a teradata table with a date field target_date (type DATE), and using a table loader I am attempting to map source_datetime to target_date. When I run the transformation I get the error
ERROR: A SAS value cannot be converted to a Teradata date
The temporary work table is populated with good data. When I attempt the conversion from DATETIME22.6 to DATE9. the output looks like "*********".
Much gratitude.
I know very little about either DIS or Teradata, but I don't think either are related to your problem.
Datetime values are the number of seconds since Jan 1, 1960 00:00:00. Date values are the number of days since Jan 1, 1960.
It sounds like you are trying to apply the date9 format to a datetime value. If you do this, it will usually look like ********* because the number of seconds is way too high to be represented as a date. If you want to keep the datetime value but have it formatted like a date, use the dtdate9 format. Otherwise, you could convert the datetime value to a date value with the datepart() function and then use the date9 format.
Related
I have a dataset where date_occur is in MMDDYY10 format (looks like 10/23/2014). I want all dates in FY17 which is 10/01/2016-09/30/2017. The following code is not working for some reason. Why!!
I'm not getting any error or warning messages I'm just getting an empty table.
Thanks in advance
data fy17;
set y16_17;
where date_occur between 10/01/2016 and 09/30/2017;
run;
The Log says:
NOTE: There were 0 observations read from the data set WORK.Y16_17.
WHERE (date_occur>=0.0001487357 and date_occur<=0.0049603175);
I'm thinking SAS is not understanding that date_occur is in mmddyy10 format. The internet has code like
where date_occur between '10/01/2016'd and '09/30/2017'd;
I tried this and it did not work either.
Your 'dates' are being interpreted as numeric expressions, and none of the date values in your table lie in the resulting range. Use date literals instead:
data fy17;
set y16_17;
where date_occur between '01oct2016'd and '30sep2017'd;
run;
You can only use date. format (ddmmmyyyy / ddmmmyy) when specifying date literals.
I've recently started using SAS Enterprise guide and would like to convert the date "01MAR2014" to "MAR 2014". I've been googling but unfortunately no luck.
I've tried the following however it just returns an
SELECT input(put(StartDate,EURDFMYw.),9.) AS Order_DDD_YY
Does anyone know how to convert this?
If your date is a SAS date, i.e. a numeric with date format applied then you can change the display by using the monyy5. format instead. Note that this will create a character variable that will no longer sort properly in reports/datasets, it will sort alphabetically instead of a date order.
put(startDate, monyy7.) as Order_DDD_YY
Otherwise you can apply the format instead of converting it.
I have a data which is in one column which has a mix of all data types, formats.
text, numeric and also date.
I have to transpose the coloumn to rows.
When I import the data in to sas 9.3 the dates are turning into a number (char format) and after transpose when I try to convert using the input function it is not giving the correct date.
The observation I am getting is like 41172 in the date column.
How do I convert it?
Think you're confusing data types and formats. The two types are character and numeric.
Dates are all numeric, and are stored as a SASDATE which is the offset from 01 JAN 1960, with each day representing 1.
To have each SASDate be displayed, you must format that variable as a date (eg. date7, ddmmyy etc). That means you first need to use the input function to go from text to numeric (SASDate) then the put function to format it as you want it.
If you're using the input function, you just need to add one of those formats and a put function:
newvar=put(input(var,8.),date7.);
Or you could leave it as just the input() and use this:
format var date7.;
In your data step.
In test_1 table, the my_date field is a "DATE9." format.
I would like to convert it to a pure numeric format (number length 8) which is of the form YYYYMMDD.
I would also like to do this in a proc sql statement ideally.
Here's what I have so far.
Clearly I need something to manipulate the my_date field.
rsubmit;
proc sql;
CREATE TABLE test_2 AS
SELECT
my_date
FROM
test_1
;
quit;
endrsubmit;
FYI: I am finding it quite difficult to understand the various methods in SAS.
To clarify, the field should actually be a number, not a character field, nor a date.
If you want the field to store the value 20141231 for 31DEC2014, you can do this:
proc sql;
create table want as
select input(put(date,yymmddn8.),8.) as date_num
from have;
quit;
input(..) turns something into a number, put(..) turns something into a string. In this case, we first put it with your desired format (yymmddn8. is YYYYMMDD with no separator), and then input it with 8., which is the length of the string we are reading in.
In general, this should not be done; storing dates as numerics of their string representation is a very bad idea. Try to stay within the date formats, as they are much easier to work with once you learn them, and SAS will happily work with other databases to use their date types as well. If you want the "20141231" representation (to put it to a text file, for example), make it a character variable.
Don't.
You lose the ability to use built in SAS functions for date calculations.
SAS stores dates as numbers, 0 being Jan 1, 1960 and increments from there. Formats are used to display the formats as desired for reporting and presentation.
In my program I need to save peoples birthday in a sqlite database. Then within the program I need to display the birthday as well as their age too.
Is their a special way to save dates in one column or do I need to save them seperatly day, month and the year.
My other question is how to get their age accurately as years, month and days. is it possible to do this with some kind of function.
The date can be stored in a single column as text, a real or an int and can be used with the builtin date functions.
Documentation:
1.2 Date and Time Datatype
SQLite does not have a storage class set aside for storing dates
and/or times. Instead, the built-in Date And Time Functions of SQLite
are capable of storing dates and times as TEXT, REAL, or INTEGER
values:
TEXT as ISO8601 strings ("YYYY-MM-DD HH:MM:SS.SSS").
REAL as Julian day numbers, the number of days since noon in Greenwich on November 24, 4714 B.C. according to the proleptic
Gregorian calendar.
INTEGER as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC. Applications can chose to store dates and times in any
of these formats and freely convert between formats using the built-in
date and time functions.
An example of selecting the users age from the database would be:
-- '2001-01-01' would be the text column where you store the birthdate
SELECT (strftime('%Y', 'now') - strftime('%Y', '2001-01-01')) - (strftime('%m-%d', 'now') < strftime('%m-%d', '2001-01-01')) AS 'Years'
[reference]
The sqlite documentation at http://www.sqlite.org/datatype3.html recommends to use ISO8601 strings. SQLite also provides some functions you can use in queries: http://www.sqlite.org/lang_datefunc.html