BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Babloo
Rhodochrosite | Level 12

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
LinusH
Tourmaline | Level 20
Again, you must separate the concept of data values and formats.
What @Kurt_Bremser 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

7 REPLIES 7
Kurt_Bremser
Super User

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.

Babloo
Rhodochrosite | Level 12

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?

LinusH
Tourmaline | Level 20
Again, you must separate the concept of data values and formats.
What @Kurt_Bremser 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
Babloo
Rhodochrosite | Level 12

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.

Tom
Super User Tom
Super User

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.

Babloo
Rhodochrosite | Level 12
My requirement is see the date values in date7. Format and I have to do
this manipulation in DI Studio.
LinusH
Tourmaline | Level 20
The best way to verify your understanding is to try it out!
Data never sleeps

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

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