Reputation: 31
I am trying to do a very easy SAS calculation such as Age=current_year- birth_year.
How do I set current year? I tried current_year=2018; but SAS does not like this answer?
I am needing to know how to set current year to 2018.
data merged_bike;
merge all_clean_data (in=a) boroughs(in=b);
by station_id;
if a and b;
run;
Current_year =2018;
Age= Current_year - birth_year;
if Age <29 then age_group ='0-29';
else if Age > 30 and age<40 then age_group= '30-39';
else if Age>40 and age<50 then age_group='40-49';
else if Age>50 and age<60 then age_group='50-59';
else if Age>60 and age<70 then age_group='60-69';
run;
Upvotes: 0
Views: 3385
Reputation: 51621
You cannot have assignment statements outside of a data step. Remove the extra run;
statement that is ending the data step definition too soon.
Or create a second data step to read the data back in and run your age calculations.
If you want today's year you can use the date()
function (or its alias today()
) and then use the year()
function to extract the year.
current_year = year(date());
Upvotes: 2