Conversion of date into char datatype

Reply
Frequent Contributor
Posts: 101

Conversion of date into char datatype

Hi,

I have source tables in oracle .For Eg (Date of Birth is in Date datatype)

When we import into SAS DI,Its taking DOB column as numeric datatype.

I need to convert that into character.

I have used put function(put(Date of Birth,10.)),but its not working.

I need that output in same form.

Date of Birth           o/p

01-Jun-1965         01-Jun-1965

How to do these?

Super User
Posts: 5,424

Re: Conversion of date into char datatype

Posted in reply to Helannivas

Since it's a date column in Oracle, you need a SAS date format, not just a plain numerical format.

Why do you want to convert it to char?

Data never sleeps
Frequent Contributor
Posts: 101

Re: Conversion of date into char datatype

My target column(DOB) is in Varchar .I need to change for sure.

What SAS date  format i need to define?

Super User
Posts: 5,424

Re: Conversion of date into char datatype

Posted in reply to Helannivas

Date.

Data never sleeps
Frequent Contributor
Posts: 101

Re: Conversion of date into char datatype


i have tried this....but its not workin

Moderator
Posts: 252

Re: Conversion of date into char datatype

Posted in reply to Helannivas

First, is the date value being returned as a DATE or a DATETIME? Best way to test is to put the value to the log

put DOB=;

Next, convert the numeric date into a character date: if DOB = 19546, then put(DOB,10.) will get "     19546".

What layout do you want your date to be, such as dd-mm-yyyy, yyyy-mm-dd? It should then be a relatively straightforward task to select the appropriate format.

Frequent Contributor
Posts: 101

Re: Conversion of date into char datatype

Posted in reply to AndrewHowell

Foe me,the date is returned as datetime first (format and unformat both as datetime).getting as 01Jun1958:00.00.00

And in table loader transformation ,I have used (put(DOB,10.)) and changing datatype column as character because i have

used put(numeric to char) function

When I change into char,i am not able to define the appropriate formats in SAS DI.

Its having format like($,$binary,$varying....not ddmmyy...)

Super User
Posts: 5,424

Re: Conversion of date into char datatype

Posted in reply to Helannivas

If its datetime, you need first to use datepart() function, before applying the date format.

Data never sleeps
Occasional Contributor
Posts: 13

Re: Conversion of date into char datatype

Posted in reply to Helannivas

Hi,

Try this  put(datepart(DOB),date11.) for SAS 9.2 and higher version.

Frequent Contributor
Posts: 101

Re: Conversion of date into char datatype

Thnks DJChavda....Its working fine

Ask a Question
Discussion stats
  • 9 replies
  • 2922 views
  • 0 likes
  • 4 in conversation