SAS: Bars in Gchart are stacked - sas

I am trying to use Gchart in SAS to plot the values I've got, here is my code:
title "WOE Trend of VarA.";
proc gchart data=work.VarA;
vbar VarB /
type=sum sumvar = VarA ASCENDING
subgroup = VarA nolegend
raxis=axis1
maxis=axis2
autoref clipref
width=32;
run;
There are four observations in table VarA, thus I expect to see four bars appear in the plot. However, in practive, there are two of the bars are stacked together that formed a stacked bar chart as follows. Also, the values of the observations are integers, however, there are decimals in the X-axis.
I guess I must have missed something in the option part since I am very new to this. Can anyone give me a clue that what am I wrong and how can I fix it? Thank you very much.

Probably what you have is
VarA Varb
42 0.75
20 0.75
35 -0.75
28 2.25
That would generate the above chart. If you didn't subgroup by VarA, you'd get a single bar 62 long for the first observation instead of splitting it partway through. Summing and subgrouping by the same variable doesn't make a whole lot of sense, to me, but it depends on what you're trying to do I suppose.
The decimals are likely in the data, and are just rounded by your format. If you want more useful help, you might post your actual data and code.

Related

Compare datasets and plot in sas

I have two variables in 2 separate datasets in sas. Both have a primary key of Customer_Id and another column say LVR . One dataset has old values for the LVR Column. The other one has values from the new calculation for the same column.
I need to show the differences between both on a graph.
I tried to merge them and then tried proc gplot to plot the two LVRs.
Merged dataset looks something like this :
Cust_id LVR_new LVR_old
111 1 2
222 2 .
333 5 4
The dataset containing LVR_new is almost twice in size (number of rows) than the one containing LVR_old.We got more customers qualifying post the new calculations.
The merged dataset has 3046778 observations and 3 variables.
I tried to use proc gplot using the code below:
proc plot data=djia;
plot LVR_old*LVR_new = Cust_id;
run;
This has been running since long so i don't expect the results are going to be very useful.
Can anyone please suggest how can I achieve this. I need to showcase the differences between the two datasets on a graph to be able to show the shift in the results.
Thanks!
Why not use PROC TTEST? There are some ODS GRAPHICS plots that PROC TTEST makes.
Your problem looks exactly liked the paired comparisons example in the documentation.
http://support.sas.com/documentation/cdl/en/statug/67523/HTML/default/viewer.htm#statug_ttest_examples03.htm
proc ttest;
paired LVR_old*LVR_new;
run;

How can I display a single pie chart in SAS using gchart

So I have seven different fields/variables in a SAS table each containing 1's and 0's. I need to - if at all possible - display these seven variables in one single pie. Is this possible? If so how? When I do this: pie variable1 variable2 / options I get two pies. Is there a way for me to combine them into one?
If your indicators reflect percentages of a whole WITHOUT overlap then yes you can.
This applies to multiple choice questions where you can select One of the Above. If it's a question that is select All that apply, then this would not be appropriate.
You cannot use the GCHART procedure but first need to summarize your data. Use a proc means to calculate the sums and then pass those to your PROC.
Proc means data = have stackods sum;
VAR ind1-ind7;
ODS OUTPUT summary=totals;
Run;
Use the TOTALS dataset in your gchart with the sum as the Pie statement. I don't recall what the variable is called.

How do I create a pie chart in SAS for a variable whose values I've grouped using PROC FORMAT?

I have a variable ideology that takes on values from 1 to 7. I've decided to make these continuous values into three groups using PROC FORMAT like so:
proc format;
value ideofmt
1-2='Lib or Extr Lib'
3-5='Mod Lib, Slight Lib or Slight Cons'
6-7='Cons or Extr Cons';
run;
I want to create a pie chart that takes into account my grouping of these continuous values, if possible without having to modify the data itself. What I've tried is:
proc gchart data=sasuser.project2;
pie ideology /noheading percent=arrow slice=inside value=inside coutline=black
woutline=2;
format ideology ideofmt.;
run;
This gets me a pie chart that has the group labels that I want, but the pie chart is split into 7 slices (corresponding to the 7 values) instead of 3 (corresponding to the 3 groups).
Any help with this would be much appreciated. Thanks!
Add the discrete option to your pie statement:
proc gchart data=sasuser.project2;
pie ideology /noheading percent=arrow slice=inside value=inside coutline=black discrete
woutline=2;
format ideology ideofmt.;
run;
quit;
Otherwise, I think SAS assigns slices based on quantiles of your data, ignoring formatted values.
Also, a quit statement is required at the end of proc gchart in addition to the run statement.

Remove overlapping X-axis labels on a barchart

Short of using annotations, I have been unable to find a reasonable way to prevent my x-axis labels from overlapping when using a barchartparm in SAS. From the documentation, they clearly state that barcharts use a discrete axis and the other axis types such as time are not permissible for them. Although conceptually this makes sense it seems like an 'unnecessary' limitation to enforce as it leaves no control over the x-axis labeling as every discrete label will be printed.
Sample data:
data test;
format rpt_date date9.;
do rpt_date=date()-90 to date();
root = round(ranuni(1) *100,1);
output;
end;
run;
Define the chart template:
proc template;
define statgraph giddyup;
begingraph;
layout overlay;
barchartparm x=rpt_date y=root ;
endlayout;
endgraph;
end;
run;
Create the chart:
proc sgrender data=test template=giddyup;
run;
Result:
I tried to be duct-tape it and create a custom format for the x-axis that would 'blank-out' many of the values, and although the chart was produced, it stacked all the blanks together (??) and also produced a warning.
I've also tried using the alternate x2axisopts and setting the axis to secondary with no luck.
If I used a series chart I would be able to control the axis fine, but in my case the data is much easier to interpret as a barchart. Perhaps they needed to add additional options to the xaxisopts for barcharts.
The most frustrating thing here is that it's something that you can do in excel in 2 seconds, and to me seems like it would be a very common chart in excel, that is not easily reproducible in SAS!
EDIT: I also don't want to use proc gchart .
Ok now I feel silly. Turns out that histograms will achieve the same result nicely:
histogramparm x=rpt_date y=root ;
Still a valuable question I guess as I spent a lot of time googling for answers and could not find a solution.
Good thing I didn't want it horizontal...

5 and 95th whiskers with sglot?

Is it possible to choose the whisker value with proc sgplot.
Because it seems only 25th and 75th are avalaible for SGPLOT.
Maybe someone know if it is possible or not?
Thanks
It is not possible to add non-standard whiskers, probably because it is discouraged by statisticians.
They discourage it because the boxplot has a specific definition in terms of the quartiles.
While there are occasional variations, (i.e., to get a rough normality plot),
in general people expect to see quartiles in a box plot.
Adding arbitrary percentiles, even ones that make sense like the ones you propose,
is likely to confuse the audience more than it helps.
Try this visualization: A waterfall graph of sales contributions based on the percentile intervals you suggest:
data actualBinned; set sashelp.prdsale;
keep actual;
run;
proc rank data=actualBinned out=actualBinned
groups=100
descending;
var actual;
ranks rank;
run;
data actualBinned; set actualBinned;
if rank < 5 then bin="00-05";
else if rank < 25 then bin="05-25";
else if rank < 50 then bin="25-50";
else if rank < 75 then bin="50-75";
else if rank < 95 then bin="75-95";
else bin="95-100";
run;
proc sort data=actualBinned;
by bin;
run;
proc sgplot data=actualBinned;
waterfall category=bin response=actual;
run;
I am not a huge fan of bins of different width displayed with the same width. I would rather use 20 bins of width 5.
With that caveat, I can see how a manager might find this visualization more useful in a specific context.
BTW, the waterfall graph is experimental in 9.3. For older version of SAS there are several recipes online.