Hi All,
I have a difficulty with SAS dates. I am trying to find the number of observations between two SAS datetime values. I have a dataset with a column datetime1 and column datetime2 and I want to see how many observations are within an hour in these two columns. For e.g.
Datetime1 DateTime2
07/13/2017:15:04 07/13/2017:16:04
I want to know how many observations are between these two datetimes. I have this statement in SAS
data new;
set test;
if input(Datetime1, mdyampm.) > input (Datetime2, mdyampm.) and input (datetime1, mdyampm.) < input(datetime2, mdyampm.)+3600;
run;
Any help is greatly appreciated!
M
What happens when you run the code? Is there an error in the LOG? (if so, please show us the log, the code AND the error messages) Or do you get the wrong answer?
Also, are datetime1 and datetime2 character variables or numeric variables?
Hi,
I'm getting an error when I run the code:
NOTE: Invalid numeric data, datetime1='9/12/2019 22:13' , at line 478 column 23.
WARNING: Limit set by ERRORS= option reached. Further errors of this type will not be printed.
I used this code:
DATA onehour2; SET matched2;
IF INPUT(datetime2, mdyampm.) > INPUT(datetime2, mdyampm.)
and
INPUT(datetime2, mdyampm.) < INPUT(datetime2, mdyampm.) + 3600;
RUN;
Datetime1 and Datetime2 are character variables
Thank you,
M
I specifically asked to see the LOG showing both the code and the error messages. Please provide that information.
And I also asked about what type of variable these datetimes are, numeric or character. Please provide that information.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.