BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Saikiran_Mamidi
Obsidian | Level 7

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?

1 ACCEPTED SOLUTION

Accepted Solutions
s_lassen
Meteorite | Level 14

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;

View solution in original post

2 REPLIES 2
ed_sas_member
Meteorite | Level 14

Hi @Saikiran_Mamidi 

 

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;
s_lassen
Meteorite | Level 14

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;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 510 views
  • 2 likes
  • 3 in conversation