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

Hi,

 

I have a data set called "Complaints".  In this dataset are columns called "Ref" and "Reason".

 

The "Ref" is a customers reference number. For each reference number there is a "Reason". This dataset can and does contain duplicate reference numbers.

 

Is there a way that I can create a new dataset and have disctinct "Ref" and create new columns for each "Reason"? Some customers can have 20 different "Reason"s.

 

Cheers

Haydn

1 ACCEPTED SOLUTION

Accepted Solutions
RahulG
Barite | Level 11

Hi

 

Hope I understood your problem correctly. Below I tried to solve it using proc transpose. 

See if this work, otherwise provide more information on how your input data looks like. 

 

data complaints;
input customer $ ref reason $20.;
datalines;
C1 101 Not happy
C1 101 Delayed Service
C1 102 High Price
C2 101 Not happy
C2 101 Delayed Service
C2 101 Prolong resolution
;
run;
proc transpose data=complaints out=transposed;
by customer ref;
var reason;
run;

 

View solution in original post

2 REPLIES 2
RahulG
Barite | Level 11

Hi

 

Hope I understood your problem correctly. Below I tried to solve it using proc transpose. 

See if this work, otherwise provide more information on how your input data looks like. 

 

data complaints;
input customer $ ref reason $20.;
datalines;
C1 101 Not happy
C1 101 Delayed Service
C1 102 High Price
C2 101 Not happy
C2 101 Delayed Service
C2 101 Prolong resolution
;
run;
proc transpose data=complaints out=transposed;
by customer ref;
var reason;
run;

 

Reeza
Super User

The second part of your question is commonly known as a transpose. 

 

You should find an option under Data Tasks to transpose the data.

 

But given your description it sounds like you may need to split your file one for REF and one for Reason? Otherwise how do you want it to look, will all the reason variables be empt for the REF records? This is a case where you need to provide sample input and output data.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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