Date compare not working in sas  - Input from Excel spreadsheet

Posted on 2013-10-28
Last Modified: 2013-10-29

I am having a problem with an Excel file being read into SAS.  When I do a proc contents on the field it is defined as DATE9.

However, my compares are not working against the date.  When the date from another file is compared to the date if it is less than it works but equal does not.

This code works fine;
Data JUN24;
      Set temp_results;
      if year(connecteddate) = 2013;
      if month(connecteddate)= 06;
      if day(connecteddate) = 24;

This code does not:
Data JUN24;
      Set temp_results;
      if connecteddate = '24JUN2013'd;

Does anyone know what the problem could be?  

My import statement looks like this

PROC IMPORT DATAFILE="C:\Documents and Settings\myfiles\My Documents\File1.xlsx" OUT=File1 DBMS=Excel REPLACE;
Question by:morinia
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 25

Assisted Solution

chaau earned 300 total points
ID: 39607181
Most likely the date in your excel file contains time component. Excel may display it as a date, because the format for the cell is set to display date only. You can always check what is in the cell by changing the format to one that has time in it.
LVL 14

Accepted Solution

Aloysius Low earned 200 total points
ID: 39607441
can you try displaying the date field (connecteddate) as a number i.e. best.? bear in mind that while the field can be defined as date9, underlying SAS stores the information as a number... there could be a decimals in the number which is not displayed

Author Comment

ID: 39608452

I have attached  a sample of the file coming in.  I have tried everything and I cannot get the dates to compare correctly.

Can someone look at the dates:  connecteddate, initateddate and see if they see what the problem is?  This is the file I am reading into SAS.
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.


Author Closing Comment

ID: 39609625
I couldn't tell what was going on.  It appeared to have time ut using datepart did not work so I just concatenated month day and year to get the date.

cdate = mdy(month(connecteddate), day(connecteddate), year(connecteddate));
LVL 14

Expert Comment

by:Aloysius Low
ID: 39610458
i have looked at the file and the imported results, and as suspected by both chaau and myself, the imported value is not a pure number - it is a date time value in excel.. when importing, SAS converts the excel date into SAS date, but leaves the Excel time component (reflected as decimals) in place..

e.g. 23 May 2013 in your Excel file has 41417.4927777778 as the number value, and when imported, SAS stores it as 19501.492778.

thus, attempting to do a direct comparison of the imported date with "23May2013"d will not work, and neither will datepart as the decimal component is not recognised as a time in SAS.. to resolve this, yes, you could use the MDY function like you have done.. the other way is use the FLOOR function which will remove the decimals

Author Comment

ID: 39610594
Thanks for the additional explanation and introducing the floor function.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question