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
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;
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;
@AstoundingThanks for such an easy solution.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.