Desktop productivity for business analysts and programmers

Create new Columns based on values from another Column

Accepted Solution Solved
Reply
Contributor
Posts: 37
Accepted Solution

Create new Columns based on values from another Column

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


Accepted Solutions
Solution
‎10-10-2016 10:07 PM
Regular Contributor
Posts: 236

Re: Create new Columns based on values from another Column

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


All Replies
Solution
‎10-10-2016 10:07 PM
Regular Contributor
Posts: 236

Re: Create new Columns based on values from another Column

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;

 

Grand Advisor
Posts: 17,329

Re: Create new Columns based on values from another Column

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.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 263 views
  • 0 likes
  • 3 in conversation