• Status: Solved
• Priority: Medium
• Security: Public
• Views: 420

SAS - plz help

Hi ee,

w - 1
variant  a    b  c  d
test1     1    1  1  1
test2     1    1  1  1
test3     1    1  1  1
test4     1    1  1  1

w-2

variant  a  b  c  d
test1     1  1  1  1
test2     1  1  1  1
test3     1  1  1  1
test4     1  1  1  1

output to be

metric              test1                                test2                      test3                             test4
cum  week1 week2        cum  week1 week2      cum  week1 week2  cum week1 week2
a            2         1          1               2        1           1            2          1         1         2         1         1
b            2         1          1               2        1           1            2          1         1         2         1         1
c            2         1          1               2        1           1            2          1         1         2         1         1
d            2         1          1               2        1           1            2          1         1         2         1         1

I am tring to using proc transpose and proc report.

plz help
0
hello214
1 Solution

Commented:
0

Author Commented:
yes. Probably. I am new to experts exchange and my friend has the account. Just found out he also asked the same question.

0

Commented:
this one is tricky because you must pivot and unpivot on the same results.
in 11g it would be easier because pivot and unpivot are built in commands but here you'll have to do it with conditional aggregationd:

try this...

SELECT   metric,
MAX(
CASE
WHEN w1.variant = 'test1' AND metric = 'a' THEN w1.a + w2.a
WHEN w1.variant = 'test1' AND metric = 'b' THEN w1.b + w2.b
WHEN w1.variant = 'test1' AND metric = 'c' THEN w1.c + w2.c
WHEN w1.variant = 'test1' AND metric = 'd' THEN w1.d + w2.d
END)
test1_cum,
MAX(
CASE
WHEN w1.variant = 'test1' AND metric = 'a' THEN w1.a
WHEN w1.variant = 'test1' AND metric = 'b' THEN w1.b
WHEN w1.variant = 'test1' AND metric = 'c' THEN w1.c
WHEN w1.variant = 'test1' AND metric = 'd' THEN w1.d
END)
test1_week1,
MAX(
CASE
WHEN w1.variant = 'test1' AND metric = 'a' THEN w2.a
WHEN w1.variant = 'test1' AND metric = 'b' THEN w2.b
WHEN w1.variant = 'test1' AND metric = 'c' THEN w2.c
WHEN w1.variant = 'test1' AND metric = 'd' THEN w2.d
END)
test1_week2,
MAX(
CASE
WHEN w1.variant = 'test1' AND metric = 'a' THEN w1.a + w2.a
WHEN w1.variant = 'test1' AND metric = 'b' THEN w1.b + w2.b
WHEN w1.variant = 'test1' AND metric = 'c' THEN w1.c + w2.c
WHEN w1.variant = 'test1' AND metric = 'd' THEN w1.d + w2.d
END)
test1_cum,
MAX(
CASE
WHEN w1.variant = 'test2' AND metric = 'a' THEN w1.a
WHEN w1.variant = 'test2' AND metric = 'b' THEN w1.b
WHEN w1.variant = 'test2' AND metric = 'c' THEN w1.c
WHEN w1.variant = 'test2' AND metric = 'd' THEN w1.d
END)
test1_week1,
MAX(
CASE
WHEN w1.variant = 'test2' AND metric = 'a' THEN w2.a
WHEN w1.variant = 'test2' AND metric = 'b' THEN w2.b
WHEN w1.variant = 'test2' AND metric = 'c' THEN w2.c
WHEN w1.variant = 'test2' AND metric = 'd' THEN w2.d
END)
test1_week2,
MAX(
CASE
WHEN w1.variant = 'test3' AND metric = 'a' THEN w1.a + w2.a
WHEN w1.variant = 'test3' AND metric = 'b' THEN w1.b + w2.b
WHEN w1.variant = 'test3' AND metric = 'c' THEN w1.c + w2.c
WHEN w1.variant = 'test3' AND metric = 'd' THEN w1.d + w2.d
END)
test3_cum,
MAX(
CASE
WHEN w1.variant = 'test3' AND metric = 'a' THEN w1.a
WHEN w1.variant = 'test3' AND metric = 'b' THEN w1.b
WHEN w1.variant = 'test3' AND metric = 'c' THEN w1.c
WHEN w1.variant = 'test3' AND metric = 'd' THEN w1.d
END)
test3_week1,
MAX(
CASE
WHEN w1.variant = 'test3' AND metric = 'a' THEN w2.a
WHEN w1.variant = 'test3' AND metric = 'b' THEN w2.b
WHEN w1.variant = 'test3' AND metric = 'c' THEN w2.c
WHEN w1.variant = 'test3' AND metric = 'd' THEN w2.d
END)
test3_week2,
MAX(
CASE
WHEN w1.variant = 'test4' AND metric = 'a' THEN w1.a + w2.a
WHEN w1.variant = 'test4' AND metric = 'b' THEN w1.b + w2.b
WHEN w1.variant = 'test4' AND metric = 'c' THEN w1.c + w2.c
WHEN w1.variant = 'test4' AND metric = 'd' THEN w1.d + w2.d
END)
test4_cum,
MAX(
CASE
WHEN w1.variant = 'test4' AND metric = 'a' THEN w1.a
WHEN w1.variant = 'test4' AND metric = 'b' THEN w1.b
WHEN w1.variant = 'test4' AND metric = 'c' THEN w1.c
WHEN w1.variant = 'test4' AND metric = 'd' THEN w1.d
END)
test4_week1,
MAX(
CASE
WHEN w1.variant = 'test4' AND metric = 'a' THEN w2.a
WHEN w1.variant = 'test4' AND metric = 'b' THEN w2.b
WHEN w1.variant = 'test4' AND metric = 'c' THEN w2.c
WHEN w1.variant = 'test4' AND metric = 'd' THEN w2.d
END)
test4_week2
FROM w1,
w2,
(SELECT 'a' metric FROM DUAL
UNION ALL
SELECT 'b' FROM DUAL
UNION ALL
SELECT 'c' FROM DUAL
UNION ALL
SELECT 'd' FROM DUAL)
WHERE w1.variant = w2.variant
GROUP BY metric
ORDER BY metric

0