proc transpose data=tem out=tem(drop=_name_);
by vol id;
run;
data tem(keep=vol from id to);
set tem;
array arr _numeric_;
from=arr(2); /* Here consider variable "vol" is numeric.*/
do i=1 to dim(arr);
if arr(i)^=0 then do;
to=arr(i);
leave;
end;
format to:ddmmyy10.
format from:ddmmyy10.
output;
end;
run;
proc print data=tem; run;
这是我的程序。 <!-- s:) --><img src="{SMILIES_PATH}/icon_smile.gif" alt=":)" title="Smile" /><!-- s:) -->
[code:1u2qw26w]proc sort data=tem;
by id vol;
run;
proc means data=tem;
by id vol;
var date;
output out=tem_result min(date)=sdate max(date)=edate;
run;[/code:1u2qw26w]
Its my code below,You can do this by using the OUTPUT statement in PROC MEANS to create the data set incloud the summarized variables like min & max of date(tem2).
Then,just select the variables and observations which you need(tem3).
[code:1o9d899k]
data tem;
input id:$1. date:yymmdd10. vol;
format date yymmdd10.;
cards;
0 20020101 0
1 20020101 10
1 20020102 10
1 20020103 10
1 20020108 9
1 20020109 9
1 20020110 9
2 20020101 9
2 20020102 8
2 20020103 14
2 20020104 8
2 20020108 11
2 20020109 11
2 20020110 12
;
proc means data=tem min max noprint;
class id vol;
var date;
output out=tem2
min=sdate
max=edata;
run;
data tem3(keep=id sdate edata vol);set tem2;
where id gt '' and vol ge 0;
run;
[/code:1o9d899k]
[code:3f4z5q7i]
proc sort data=tem;
by id date vol;
run;
data new;
retain id s_date e_date vol;
set tem;
by id vol notsorted;
if first.vol then s_date=date;
if last.vol then do;
e_date=date;
output; end;
format s_date e_date yymmdd10.;
drop date;
run; [/code:3f4z5q7i]