BookmarkSubscribeRSS Feed
Suminder
Calcite | Level 5

Hi Guys,

I have following datasets
dataset1
nameid   name              sportsPlayed
1             sam               cricket|football|badminton
2             ravi                cricket|chess

The output sas table has to be
outputDATASET
nameid     name       sportsPlayed 
1               sam         cricket
1               sam          football
1               sam          badminton
2               ravi           cricket
2               ravi           chess

I tried using sort and 'by' but ...

Thanks in advance

2 REPLIES 2
r_behata
Barite | Level 11
data have;
input nameid  name $ sportsPlayed :$50.;
cards;
1 sam cricket|football|badminton
2 ravi cricket|chess
run;


data want;

set have(rename=(sportsPlayed=sportsPlayed_));
length sportsPlayed $15.;
do _n_=1 to countw(sportsPlayed_,'|');
	sportsPlayed=scan(sportsPlayed_,_n_,'|');
	output;
end;

drop sportsPlayed_;
run;
ballardw
Super User

@Suminder wrote:

Hi Guys,

I have following datasets
dataset1
nameid   name              sportsPlayed
1             sam               cricket|football|badminton
2             ravi                cricket|chess

The output sas table has to be
outputDATASET
nameid     name       sportsPlayed 
1               sam         cricket
1               sam          football
1               sam          badminton
2               ravi           cricket
2               ravi           chess

I tried using sort and 'by' but ...

Thanks in advance


So why did you ask how to put them in that hard to use format in the first place in this topic  https://communities.sas.com/t5/SAS-Programming/Pivot-multiple-values-of-same-column-into-one-column-...

 

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 803 views
  • 1 like
  • 3 in conversation