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

As you can see in Figure 1 below, some of the track ids are repetitive. I would want to move the repetitive row's genre into another column called genre2. Figure 2 is the result I want. 

 

Figure 1

karenktq_0-1621609070542.png

 

Figure 2

karenktq_0-1621610121495.png

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Example with made up data

 

data have;
input track_id & $12. year genre $16.;
cards;
track_id1  2017 Dance/Electronic
track_id1  2017 Pop
track_id2  2018 Reggae/Ska
track_id3  2015 Country
track_id3  2015 Pop
;
proc transpose data=have out=want prefix=genre;
    by track_id year;
    var genre;
run;

Caution: In SAS, long data sets are usually easier to work with and superior in many ways to wide data sets like the one you say you want. You need to carefully consider what you are doing and be sure that you need a wide data set (because I don't think you do in most cases). If you just want a report, or to put the data into an Excel file, that's usually the only reason to create a wide data set.

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Example with made up data

 

data have;
input track_id & $12. year genre $16.;
cards;
track_id1  2017 Dance/Electronic
track_id1  2017 Pop
track_id2  2018 Reggae/Ska
track_id3  2015 Country
track_id3  2015 Pop
;
proc transpose data=have out=want prefix=genre;
    by track_id year;
    var genre;
run;

Caution: In SAS, long data sets are usually easier to work with and superior in many ways to wide data sets like the one you say you want. You need to carefully consider what you are doing and be sure that you need a wide data set (because I don't think you do in most cases). If you just want a report, or to put the data into an Excel file, that's usually the only reason to create a wide data set.

--
Paige Miller
karenktq
Calcite | Level 5

Hi, I am actually planning to concatenate the two columns, genre and genre2 (eg; Dance/Electronic/Pop) but I could not do so from the start. I figured separating them into two columns as the first step would be much easier for me to concatenate. Thank you so much!

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
  • 531 views
  • 1 like
  • 2 in conversation