Hi all,
I need to find retirees who have worked for 25 or more years for the airline company. If you want to, you can use December 31, 2016 as a point of reference.
My data step is :
data hw3.retirees25;
infile "&path/retirees2017.txt" dlm=' ';
length LastName $ 10 FirstName $ 11 HD $ 10;
input Department$12. HD$ ES ID$ LastName$ FirstName$;
label HD="Hire Date"
ES="Ending Salary"
ID="EmployeeID";
years=int(yrdif(HD,12/31/2016,'ACT/365'));
where years >= 25;
run;
However, it shows: ERROR: No input data sets available for WHERE statement.
Could anyone help me how I could find those people work over 25 years?
When you are reading from raw data (INFILE / INPUT), the WHERE statement is illegal. Just change WHERE to IF.
'31Dec2016'd
You specify dates in SAS as a date literal, see above. Replace your date in the INTCK function with a date in the format above.
First of all . Function yrdif() require DATE type arguments. But yours is character type.
data hw3.retirees25;
infile "&path/retirees2017.txt" dlm=' ';
length LastName $ 10 FirstName $ 11 HD $ 10;
input Department$12. HD : mmddyy12. ES ID$ LastName$ FirstName$;
label HD="Hire Date"
ES="Ending Salary"
ID="EmployeeID";
years=int(yrdif(HD,'31dec2016'd,'ACT/365'));
if years >= 25;
run;
After I changed that, I could not print out in the next part. I must let the date shows in character way, it is the original one I did not asked to change that. So is there another way, I could caculate years between them and only show years >= 25?
So far, you're doing the right thing. The way you print a date in as "characters" is to apply a format. This statement could become part of the DATA step, or it could become part of the next step that prints the data (either way is fine):
format hd mmddyy10.;
There are many other date formats you can choose from. Here are just a few samples:
format hd date9.;
format hd yymmdds10.;
data hw3.retirees25;
infile "&path/retirees2017.txt" dlm=' ';
length LastName $ 10 FirstName $ 11 HD $ 10;
if HD <= "12/31/1991";
input Department$12. HD$ ES ID$ LastName$ FirstName$;
label HD="Hire Date"
ES="Ending Salary"
ID="EmployeeID";
format ES comma7.;
run;I tried another way, but it still show all my observations.
Comparing dates in strings will most likely not give the expected result. The subetting if-statement ist misplaced, move it below the input statement.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Get started using SAS Studio to write, run and debug your SAS programs.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.