标题: 帮我看看这道题 [打印本页] 作者: shiyiming 时间: 2007-9-9 21:51 标题: 帮我看看这道题 name birthday gender which race time
Smith, James 03-09-91 M 1 00:39:42
Smith, James 03-09-91 M 2 00:38:25
Anderson, Jim 05-27-79 M 1 00:36:10
Anderson, Jim 05-27-79 M 2 00:36:52
Milton, Karen 10-23-71 F 1 00:42:36
Milton, Karen 10-23-71 F 2 00:44:01
Cooper, Frances 02-13-82 F 1 00:46:47
(这个数据只是一部分)
就是说有两个比赛,有的人参加一次,也参加了另一次,还给出了每次所用的时间。
现在要求:
restructure the data set so there is only observation per runner with the
observation giving the name of the runner ,their sex ,age ,age group (Youth,
adult ,or Senior),the times for the two races and the best time.Print(
display)this new data set.
Female Youth(16 and under) Female Adult(17-49) Female Senior (50 and over) -
----
data race;
input name: $15. birthday: mmddyy8. gender $ whichrace time: time8.;
format birthday mmddyy8. time time8.;
age=intck('year',birthday,today());
if (.<age<=16) then agegroup='Youth';
else if (17<=age<=49) then agegroup='Adult';
else if (50<=age) then agegroup='Senior';
datalines;
Smith,James 03-09-91 M 1 00:39:42
Smith,James 03-09-91 M 2 00:38:25
Anderson,Jim 05-27-79 M 1 00:36:10
Anderson,Jim 05-27-79 M 2 00:36:52
Milton,Karen 10-23-71 F 1 00:42:36
Milton,Karen 10-23-71 F 2 00:44:01
Cooper,Frances 02-13-82 F 1 00:46:47
;
run;
proc sql;
create table onlyrace as
select name, birthday, gender, whichrace,max(whichrace) as racetimes, time, age, agegroup from race
group by name
order by name, time;
quit;
data onlyrace;
set onlyrace;
retain besttime;
by name time;
if first.name then besttime=time;
format besttime time8.;
run;
data onlyrace;
set onlyrace;
by name;
retain time1-time2;
array ttime{2} time1-time2;
if first.name then
do i = 1 to 2;
ttime{i} = .;
end;
ttime{whichrace} = time;
if last.name;
format time1-time2 time8.;
drop i time;
run;作者: shiyiming 时间: 2008-1-5 19:32 标题: Re: 帮我看看这道题 data a;
input name: $15. birthday:mmddyy8. gender $ which race_time time8.;
cards;
Smith,James 03-09-91 M 1 00:39:42
Smith,James 03-09-91 M 2 00:38:25
Anderson,Jim 05-27-79 M 1 00:36:10
Anderson,Jim 05-27-79 M 2 00:36:52
Milton,Karen 10-23-71 F 1 00:42:36
Milton,Karen 10-23-71 F 2 00:44:01
Cooper,Frances 02-13-82 F 1 00:46:47
;
proc sort data=a;
by name birthday;
run;
data b(drop=birthday race_time rename=(gender=sex));
length age_group $ 6;
set a(drop=which);
by name birthday;
retain best_time;
if first.birthday then best_time=race_time;
if race_time<best_time then best_time=race_time;
if last.birthday then do;
age=intck('year',birthday,today());
if age<16 then age_group='Youth';
else if age<=50 then age_group='Adult';
else age_group='Senior';
output;
end;
format best_time time8.;
run;