SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Converting yyyymmdd. to DATE9.?

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 89
Accepted Solution

Converting yyyymmdd. to DATE9.?

I'm working in DI Studio, and have trouble changing the format of a numeric variable.

My input table has a numeric variable with the format yyyymmdd. Value example: 20130531.

I need to convert it to the DATE9. format, so that it displays as 31MAY2013.

What kind of expression can I use for this?

I tried using this:

input(put(DUE_DT, yyyymmdd.),date9.)

However, the values only become blank/null.

Thanks for your time!


Accepted Solutions
Solution
‎06-10-2013 06:01 AM
Super User
Posts: 5,255

Re: Converting yyyymmdd. to DATE9.?

Ok, so you date values are not stored as SAS dates. Then datepart will definitely not work.

So, apart from specifying date9. on the target column, you need to transform the value, as in your initial post.

First, there is not format called yyyymmdd., it's called yymmdd.

In your case, the data is already stored in a read friendly format, so use 8. format in the put statement instead, and yymmdd8. on the input.


Data never sleeps

View solution in original post


All Replies
Super User
Posts: 10,474

Re: Converting yyyymmdd. to DATE9.?

If your values are a SAS date value the statement would be: format variablename date9.;

If not then the assignment should be

 

input(put(due_dt,f8.0),yymmdd.);

The put(due_dt, yyyymmdd.) has two problems in your case, first the format would be yymmdd. , second if the value isn't a date value then your results are going to be very unpredictable, and in this case it would represent a day in the future well past the range of dates SAS will manipulate


Super User
Posts: 5,255

Re: Converting yyyymmdd. to DATE9.?

What you mean by convert?

Basically,  just specify the required format in target table properties.

Data never sleeps
Frequent Contributor
Posts: 89

Re: Converting yyyymmdd. to DATE9.?

Thanks, but if I simply specify DATE9 as the target table column format, all the values show up as " ********* ". Incompatible date formats, I think.

Incidentally, if I use the expression datepart(due_dt) and the DATE9 format in the target table, all date values display as "20AUG1960" (correct format, wrong values).

EDIT: If I force it to have the 8.0 format, the values still appear as "20130531".

Solution
‎06-10-2013 06:01 AM
Super User
Posts: 5,255

Re: Converting yyyymmdd. to DATE9.?

Ok, so you date values are not stored as SAS dates. Then datepart will definitely not work.

So, apart from specifying date9. on the target column, you need to transform the value, as in your initial post.

First, there is not format called yyyymmdd., it's called yymmdd.

In your case, the data is already stored in a read friendly format, so use 8. format in the put statement instead, and yymmdd8. on the input.


Data never sleeps
Frequent Contributor
Posts: 89

Re: Converting yyyymmdd. to DATE9.?

Worked like a charm, many thanks!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 52903 views
  • 10 likes
  • 3 in conversation