Solved

Date compare not working in sas  - Input from Excel spreadsheet

Posted on 2013-10-28
6
418 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 24

Assisted Solution

by:chaau
chaau earned 300 total points
Comment Utility
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 200 total points
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Closing Comment

by:morinia
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for the additional explanation and introducing the floor function.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now