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

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
Asked:
hello214
1 Solution
 
Aloysius LowCommented:
0
 
hello214Author Commented:
yes. Probably. I am new to experts exchange and my friend has the account. Just found out he also asked the same question.

Sorry for the repetition can you please help.
0
 
sdstuberCommented:
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
 
DavidSenior Oracle Database AdministratorCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now