I'm doing a SAS EG question which is asking for the year, orginal data Employee_Hire_Date
provided in the table is formatted like 01JAN1960
, I'm trying using (01/01/2012 - date)/365.25
and the result returned seems to be an wrong answer. What should I do?
proc sql;
/* Question 1 */
select Employee_ID, Salary format=dollar12.2, (Employee_Hire_Date - 01/01/2012)/365.25 'Duration(Year)' format=number6.2
from employee_information
where Job_Title = 'Sales Rep. I'
having Employee_Hire_Date > 31/12/1979 and Employee_Term_Date = .
order by Salary desc;
quit;
CodePudding user response:
You need to provide dates as a date literal in SAS, which means like '01Jan2022'd.
proc sql;
/* Question 1 */
select Employee_ID, Salary format=dollar12.2, (Employee_Hire_Date - '01Jan2012'd)/365.25 'Duration(Year)' format=number6.2
from employee_information
where Job_Title = 'Sales Rep. I'
having Employee_Hire_Date > '31Dec1979'd and Employee_Term_Date = .
order by Salary desc;
quit;
I would recommend looking into INTCK as well if you're looking to calculate differences in dates rather than just using plain math.