i am having data like this
tid tname$ time subt$
1 abc 20:12 xy,zx,yz
i want the above observation like this
tid tname$ time subt$
1 abc 20:12 xy
1 abc 20:12 zx
1 abc 20:12 yz
only code required?
That's not so hard:
data want;
set have;
length _subt $2;
do _N_=1 to countw(subt);
_subt=scan(subt,_N_,',');
output;
end;
drop subt;
rename _subt=subt;
run;
Here is an attempt to do this:
data have;
input tid tname$ time:time5. subt:$80.;
format time time5.;
datalines;
1 abc 20:12 xy,zx,yz
2 edf 20:12 aa,zx,yz,rb,rb
;
run;
proc sql noprint;
select max(countw(subt,',')) into: max_nb from have;
quit;
data have2;
set have;
nb = countw(subt,',');
array _subt(&max_nb) $ ;
do i=1 to nb;
subt_new = scan(subt,i,',');
output;
end;
drop i nb subt _subt:;
rename subt_new = subt;
run;
That's not so hard:
data want;
set have;
length _subt $2;
do _N_=1 to countw(subt);
_subt=scan(subt,_N_,',');
output;
end;
drop subt;
rename _subt=subt;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.