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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

Register now

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