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

I am using the IOM provider to read data from a SAS Base library into a .NET C# application. The problem arises when reading columns defined as Date values. When reading unformatted objects, the date values are returned as double floating point numbers. I need a function to transform the number to a .NET DateTime object.

 

I know I can instrument the IOM provider to return formatted string objects by setting

      ADODB.Recordset.Properties["SAS Formats"] = "_ALL_";

If I use this to have formatted objects returned, there is a performance degrade, it runs 100 times slower. Due to this I was hoping I could used unformatted objects and transform the number to DateTime objects in the .NET world. Is there a .NET library with SAS date functions that can do this?

 

See case [SAS 7613337300] for more info.

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

You might need to do this transformation yourself.  Here's an example for going the other way (Microsoft datetime to SAS).

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.

View solution in original post

2 REPLIES 2
ChrisHemedinger
Community Manager

You might need to do this transformation yourself.  Here's an example for going the other way (Microsoft datetime to SAS).

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.
ReidarDMidtun
Fluorite | Level 6

Once I got the recipe, making a transform from a SAS date value was easy. 

 

A SAS datetime value is: The number of seconds since 12:00 midnight on January 1, 1960.

This value has to be mapped to a .NET DateTime value. This value is the number of ticks since 12:00 midnight, January 1, 0001 A.D. (C.E.) in the Gregorian Calendar. A tick is 100 nanoseconds.

 

Here is the transform function written in C#:

 

   private DateTime SASBaseDate = new DateTime(1960, 01, 01);
   private const long TicksInASecond = 10000000;
   private DateTime ToDate(object sasTics) {
      if (sasTics == null || sasTics is DBNull)
         return DateTime.MinValue;
       var lTicks = Convert.ToInt64(sasTics);
       return new DateTime(SASBaseDate.Ticks + (lTicks * TicksInASecond));
   }

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 492 views
  • 1 like
  • 2 in conversation