Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Date compare not working in sas  - Input from Excel spreadsheet

Posted on 2013-10-28
6
Medium Priority
?
440 Views
Last Modified: 2013-10-29
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
Comment
Question by:morinia
  • 3
  • 2
6 Comments
 
LVL 25

Assisted Solution

by:chaau
chaau earned 1200 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.
0
 
LVL 14

Accepted Solution

by:
Aloysius Low earned 800 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
0
 

Author Comment

by:morinia
ID: 39608452
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
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 

Author Closing Comment

by:morinia
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));
0
 
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
0
 

Author Comment

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

Featured Post

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
How much do you know about the future of data centers? If you're like 50% of organizations, then it's probably not enough. Read on to get up to speed on this emerging field.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

971 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