@Windata wrote: You should specify the date9. format in the first data step - see below. Also, I think you can do the where clause in the same data step as well. data a; set casesdat.cases; format discharge date9.; discharge = DatePart(Date_Discharged); where '01jan2020'd <= discharge <= '20dec2020'd; run;
You cannot reference the derived variable in the WHERE clause. The where clause filters the data on the way into the data step, so it happens before DISCHARGE is created.
You could use a subsetting IF instead.
Or reference the original variable in the WHERE clause. Either using appropriate datetime literals or using the DATEPART() function.
if '01jan2020'd <= discharge <= '20dec2020'd;
where '01jan2020:00:00'dt <= Date_discharged < '21dec2020:00:00'dt;
where '01jan2020'd <= datepart(Date_discharged) <= '20dec2020'd;
... View more