我正在尝试进行一项非常简单的SAS计算,例如Age = current_year- birth_year。
如何设定当年?我试过current_year = 2018;但SAS不喜欢这个答案吗?
我需要知道如何将当前年份设定为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;
答案 0 :(得分:2)
您不能在数据步骤之外使用赋值语句。过早删除结束数据步骤定义的额外run;
语句。
或创建第二个数据步骤以重新读取数据并运行年龄计算。
如果您想要今天的年份,可以使用date()
功能(或其别名today()
),然后使用year()
功能提取年份。
current_year = year(date());