OK. I notice your date date2 has the same value ,So I do not process them.
Look this:
[pre]
data temp;
infile datalines truncover dsd dlm=' ';
input name $ no date : mmddyy10. code $ no2 date2 : mmddyy10. code2 $;
format date date2 mmddyy10.;
datalines;
A 20 1.5.2011 sc2000 50 1.5.2011 TT2000
A 30 1.5.2011 sc6000 80 1.5.2011 TT0000
A 60 1.5.2011 sc2000 1.5.2011
B 20 1.5.2011 sc2000 30 1.5.2011 TT2000
B 40 1.5.2011 sc2000 50 1.5.2011 TT0000
C 20 4.5.2011 sc2000 50 4.5.2011 TT2000
C 60 4.5.2011 sc2000 80 4.5.2011 TT0000
C 70 4.5.2011 sc3000 4.5.2011
;
run;
data op(where=(no_value is not missing));
set temp;
array n{*} no:; array d{*} date:; array c{*} $ code:;
do i=1 to dim(n);
no_name=vname(n{i});date_name=vname(d{i});code_name=vname(c{i});
no_value=n{i};date_value=d{i};code_value=c{i};
output;
end;
drop i ;
run;
proc sort data=op;
by name no_value;
run;
data op;
set op;
by name no_name notsorted;
length no_char code_char $ 50;
retain no_char code_char;
if first.no_name then call missing(no_char,code_char);
no_char=catx(',',no_char,no_value);
code_char=catx(',',code_char,code_value);
if no_name eq 'no' then flag+1;
if last.no_name then do;
_name=catx(',',name,flag);
output;
end;
run;
proc transpose data=op out=want1(keep=_name no no2);
by _name;
id no_name ;
var no_char ;
run;
proc transpose data=op out=want2(keep=_name code code2);
by _name;
id code_name ;
var code_char;
run;
proc transpose data=op out=want3(keep=_name date date2);
by _name;
id date_name;
var date_value;
run;
data want;
merge want1 want2 want3;
by _name;
format date date2 mmddyy10.;
run;
data want;
set want;
length name $ 20;
name=scan(_name,1,',');
drop _name ;
run;
*re-order of variables;
data want;
retain name no date code no2 date2 code2;
set want;
run;
[/pre]
Ksharp