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

Formatting dates

Accepted Solution Solved
Reply
Super Contributor
Posts: 625
Accepted Solution

Formatting dates

I've used the following code to convert the date to the format date7. But after executing the code I'm receiving value as *******.

 

Variable  feemisio is a datevalue which has informats datetime23. Example: 21FEB2018:16:54:00

 

 

proc print data=temp;
format feemisio date7.;
run;

 

Appreciate if someone of you help me to resolve the issue.

 


Accepted Solutions
Solution
‎03-13-2018 01:39 AM
Super User
Posts: 5,853

Re: Formatting dates

Again, you must separate the concept of data values and formats.
What @KurtBremser says is that you need to change the data value before you can apply the format required.
You don't need a user written transformation. You need to use a mapping expression like the datepart function. Can be used in many transformations like Table Loader, Extract and SQL Join.
Data never sleeps

View solution in original post


All Replies
Super User
Posts: 9,940

Re: Formatting dates

[ Edited ]

I guess you have already been told this repeatedly.

 

You cannot use a date format on a datetime value.

 

The reason being that datetime values are a count of seconds from 1960-01-01T00:00:00, while date values are a count of days from 1960-01-01.

So, for any given date, the datetime is 86400 * date!

 

If you want to convert a datetime value to a date value, use the datepart() function in the same step where you assign the date format.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super Contributor
Posts: 625

Re: Formatting dates

Posted in reply to KurtBremser

How I can deal this in SAS DI studio without using user written transformation? Will it works if I change only the format for the variable under mapping tab?

Solution
‎03-13-2018 01:39 AM
Super User
Posts: 5,853

Re: Formatting dates

Again, you must separate the concept of data values and formats.
What @KurtBremser says is that you need to change the data value before you can apply the format required.
You don't need a user written transformation. You need to use a mapping expression like the datepart function. Can be used in many transformations like Table Loader, Extract and SQL Join.
Data never sleeps
Super Contributor
Posts: 625

Re: Formatting dates

If I understand correctly, I need to use the expression like datepart(feemisio) under mapping tab of the target table for the respective variable. Then I will change the format to date7. under format column of the respective variable.

Super User
Super User
Posts: 7,945

Re: Formatting dates

If you want to display just the date part of a datetime value you can use the DTDATE format.

 

PS. Don't use width of 7. Use a width of 9 (or 11) so that you can see the century part of the year.

Super Contributor
Posts: 625

Re: Formatting dates

My requirement is see the date values in date7. Format and I have to do
this manipulation in DI Studio.
Super User
Posts: 5,853

Re: Formatting dates

The best way to verify your understanding is to try it out!
Data never sleeps
☑ This topic is solved.

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

Discussion stats
  • 7 replies
  • 301 views
  • 6 likes
  • 4 in conversation