DATA Step, Macro, Functions and more

Transpose a dataset and create buckets

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 18
Accepted Solution

Transpose a dataset and create buckets

[ Edited ]

I have input data like this:

 

CLIENT_IDPRDR1R2TR1TR2
112A1010
112B0.500.80

 

 I want to create bucket out of this data by creating a separate variable called Metric. The dataset should look like this:

 

CLIENT_IDPRDMETRICBUCKET1BUCKET2
112AR10
112ATR10
112BR0.50
112BTR0.80
     

 

Thanks

Chandan Mishra

 


Accepted Solutions
Solution
‎09-22-2017 05:20 PM
Super User
Posts: 6,622

Re: Transpose a dataset and create buckets

Posted in reply to chandan_mishra

It looks like you need:

 

data want; 

set have;

length metric $ 2;

METRIC = 'R';

BUCKET1 = R1;

BUCKET2 = R2;

output;

METRIC = 'TR';

BUCKET1 = TR1;

BUCKET2 = TR2;

output;

keep CLIENT_ID PRD METRIC BUCKET1 BUCKET2;

run;

View solution in original post


All Replies
Solution
‎09-22-2017 05:20 PM
Super User
Posts: 6,622

Re: Transpose a dataset and create buckets

Posted in reply to chandan_mishra

It looks like you need:

 

data want; 

set have;

length metric $ 2;

METRIC = 'R';

BUCKET1 = R1;

BUCKET2 = R2;

output;

METRIC = 'TR';

BUCKET1 = TR1;

BUCKET2 = TR2;

output;

keep CLIENT_ID PRD METRIC BUCKET1 BUCKET2;

run;

Occasional Contributor
Posts: 18

Re: Transpose a dataset and create buckets

Posted in reply to Astounding

@AstoundingThanks for such an easy solution.

 

☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 177 views
  • 0 likes
  • 2 in conversation