## Transpose a dataset and create buckets

Solved
Occasional Contributor
Posts: 18

# Transpose a dataset and create buckets

[ Edited ]

I have input data like this:

 CLIENT_ID PRD R1 R2 TR1 TR2 112 A 1 0 1 0 112 B 0.5 0 0.8 0

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

 CLIENT_ID PRD METRIC BUCKET1 BUCKET2 112 A R 1 0 112 A TR 1 0 112 B R 0.5 0 112 B TR 0.8 0

Thanks

Chandan Mishra

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

## Re: Transpose a dataset and create buckets

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;

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

## Re: Transpose a dataset and create buckets

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

@AstoundingThanks for such an easy solution.

☑ This topic is solved.