1.利用intck函数,
身份证的第7-14位是出生年月日。以身份证号442423199102280873为例:
data aa;
input x $ 7-14;
y=input(x,yymmdd10.);
age=intck('year',y,date());
cards;
442423199102280873
;
run;
得到的age变量就是年龄。
2.input+substr
options nodate; /*删除每页顶部的日期*/
data pieces_parts;
input id $ 1-18;
length num $ 4;
num = 2017-input(substr(id,7,4),4.); /*得到的num变量就是年龄*/
put num;
datalines;
442423199102280873
;
title "Listing of Data Set pieces_parts";
proc print data= pieces_parts noobs;
run;
身份证的第7-14位是出生年月日。以身份证号442423199102280873为例:
data aa;
input x $ 7-14;
y=input(x,yymmdd10.);
age=intck('year',y,date());
cards;
442423199102280873
;
run;
得到的age变量就是年龄。
2.input+substr
options nodate; /*删除每页顶部的日期*/
data pieces_parts;
input id $ 1-18;
length num $ 4;
num = 2017-input(substr(id,7,4),4.); /*得到的num变量就是年龄*/
put num;
datalines;
442423199102280873
;
title "Listing of Data Set pieces_parts";
proc print data= pieces_parts noobs;
run;