Hello,
I have a field which contains both time and date, ex: "2018-10-20 10:30"
Does anyone know how I can select only date with condition like the following:
proc sql;
select date_time as date between '2018-01-01' and '2018-01-31"
Thank you!
Whats the type and format of the datetime variable?
If it's a number with a datetime format then you can use:
where datepart(date) betweeen '01Jan2018'd and '31Jan2018'd;
@parmis wrote:
Hello,
I have a field which contains both time and date, ex: "2018-10-20 10:30"
Does anyone know how I can select only date with condition like the following:
proc sql;
select date_time as date between '2018-01-01' and '2018-01-31"
Thank you!
datepart: http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000245883.htm
i don't know why you'd need to use the condition, extract the date, keep what you want, discard what you don't
Whats the type and format of the datetime variable?
If it's a number with a datetime format then you can use:
where datepart(date) betweeen '01Jan2018'd and '31Jan2018'd;
@parmis wrote:
Hello,
I have a field which contains both time and date, ex: "2018-10-20 10:30"
Does anyone know how I can select only date with condition like the following:
proc sql;
select date_time as date between '2018-01-01' and '2018-01-31"
Thank you!
Thank you very much
To compare with datetime values you need to use datetime literals.
select date_time
from have
where date between "01JAN2018:00:00"dt and "31DEC2018:23:59"dt
;
Or convert it to a date and use date literals.
select date_time
from have
where datepart(date) between "01JAN2018"d and "31DEC2018"d
;
Note that the literals must use a format that is recognized by the DATE (or DATETIME) informat.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.