3

Hi I have a problem creating a graph in SAS. my data is as follow: Date, comp_1,comp_2, comp_3, total_value. My data is sorted by dates. the variable comp_ represent the value of the company at a specific data. This is my code at the moment:

proc gplot data=dev2.Actionfinal2;
    plot (comp_1 comp_2 comp_3)*date 
         / overlay areas=3 vaxis=0 to 100000 by 20000;
    symbol1 i=join v= cv= ci=red;
    symbol2 i=join v= cv= ci=blue;
    symbol3 i=join v= cv= ci=green;
run; 
quit;

This graph show me the 3 companies value overlayed, but I want them stacked so I can see the total value of the companies for each dates. Do I need to reformat my data, what option can I use ?

BellevueBob
  • 9,498
  • 5
  • 29
  • 56

1 Answers1

3

You will need to create a new variable with the aggregated value of your three "comp" variables. See this SAS usage note with a great example. That should get you started and welcome to StackOverflow!

UPDATE: I think I better understand the problem: you need to denormalize your data (turn the columns into observations). So try this:

data test(keep=company value date);
  set dev2.Actionfinal2;
  company = 1; value = comp_1; output;
  company = 2; value = comp_2; output;
  company = 3; value = comp_3; output;
run;

proc sort data=test;
   by date company;
run;

data test2;
   set test;
      by date;
   if first.date then new_y=0;
   new_y + value;
run;

symbol1 i=join v= cv= ci=red;
symbol2 i=join v= cv= ci=blue;
symbol3 i=join v= cv= ci=green;

proc gplot data=test2;
    plot new_y*date=company 
         / areas=3 vaxis=0 to 100000 by 20000;
run; 
quit;
BellevueBob
  • 9,498
  • 5
  • 29
  • 56
  • Nice it give me what i need ! thanks a lot!! The graph in SAS is perfect, I may have one more follow up question. I want the final result to be in PDF format so I used a classic ODS PDF statement, but instead of having the same graph as in SAS it produce a PDF document with 3 graphs for each company ... Do I need to specify an option to get the same result? – Alexandre Forest Boucher Nov 03 '12 at 19:49
  • 1
    I'm sorry, but I'm not very talented with respect to ODS. In any case, your best bet is to ask another S/O question specific to this new issue. You can refer back to this question (give a link), but provide an example of the `PROC GPLOT` and `ODS` statements you have tried. I'm sure you will get a good reply. Also, please "accept" this answer if you are satisfied (so it shows up as "answered"). – BellevueBob Nov 03 '12 at 20:12