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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.