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
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;
@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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.