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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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