Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with sas dates and proc sql

Status
Not open for further replies.

imarosel

Technical User
Jun 23, 2005
149
US
Ok, I thought I had the sas date thing licked. I'm importing dates from CSVs into SAS datasets using the input function. So now I have number of seconds from 1960 or whatever. I thought doing comparisons on dates after this would be a breeze but it is not. I thought I would start by selecting the max time from my data set with proc SQL.

I'm inputing to datetime20.

proc sql;
select max(date_field) from dataset;
quit;

this returns a number in scientific notation, not sure if the accuracy of the number is lopped off.

when I try and do a compare to another datetime, I use the exact same input() to get both date times, I get an error saying the datatypes aren't the same.

proc sql;
select max(date_field) from dataset WHERE date_field < compare_date;
quit;

Am I missing something big here?
 
My solution to the first problem was using (format=datetime20.)

the solution to my second problem was I was using a macro variable and didn't have the &.

Thanks
 
Yup, that'd do it. :)

Generally I avoid using the Datetime format. I prefer to use a date field and a time field separately. You can use the DATEPART() and TIMEPART() functions to get those bits out of the data.
That's more of a personal preference thing though.

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
I'll keep that in mind, when you need to do a comparison against the whole timestamp how do you bring the two together?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top