Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 442
  • Last Modified:

Date compare not working in sas - Input from Excel spreadsheet

Experts,

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;
run;
Data JUN24;
      Set temp_results;
      if year(connecteddate) = 2013;
      if month(connecteddate)= 06;
      if day(connecteddate) = 24;
run;

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

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;
RUN;
0
morinia
Asked:
morinia
  • 3
  • 2
2 Solutions
 
chaauCommented:
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.
0
 
Aloysius LowCommented:
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
0
 
moriniaAdvanced Analytics AnalystAuthor Commented:
Experts,

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.
Date-issue.xlsx
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
moriniaAdvanced Analytics AnalystAuthor Commented:
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));
0
 
Aloysius LowCommented:
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
0
 
moriniaAdvanced Analytics AnalystAuthor Commented:
Thanks for the additional explanation and introducing the floor function.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now