08-19-2016 04:46 AM
I have a data table that stores each year, month and day value as ints:
year | month | day2009 | 1 | 1 2008 | 12 | 2 2007 | 5 | 5
I need to convert it to datetime value, because I need to use it in a datetime between operation. How could I do this?
08-19-2016 04:54 AM
08-19-2016 04:54 AM
08-19-2016 05:09 AM - last edited on 08-19-2016 05:42 AM by KurtBremser
Thanks for giving reply,Actually question was wrongly posted, Below i posted question
Year Month Day
2009 01 01
2008 12 02
2007 05 05
These values are in different columns, so i want to
combine these variables to get date value in character format
08-19-2016 05:47 AM
The leading zeros make me believe that you already have the values stored in variables of type character.
If this is so, a simple concatenation will do the trick:
newvar = year !! '-' !! month !! '-' !! day;
If this produces unwanted blanks (because the variables are defined longer thatn necessary), use the strip() function to get rid of them.
If your values are actually stored as numbers, this will create the same character value:
newvar = put(mdy(year,day,month),yymmddd10.);
The third "d" in the format specifies the separator character (dash)
08-19-2016 05:59 AM
08-19-2016 06:05 AM
SAS complains about a missing $.... format. This means that you tried to apply the numeric format YYMMDDD10. to a character variable. In such a case SAS assumes that you mistyped and adds the $ for a character format on its own. This is then not found.
SAS date and datetime formats must be applied to numeric variables that hold date (days since 1960-01-01) or datetime (seconds since 1960-01-01:00:00:00) values.
08-19-2016 07:16 AM
Actually i want the variable in charcter format with requried date format.
Is not possible. To apply a date/datetime format, the variable MUST be numeric.
But you can use the format to convert the value in the numeric variable to a character value, and store that in a separate character variable:
data test; format date_num yymmddd10.; date_num = date(); date_char = put(date_num, yymmddd10.); date_num_raw = date_num; run; proc print noobs; run;
date_ date_num date_char num_raw 2016-08-19 2016-08-19 20685
Need further help from the community? Please ask a new question.