Plotting a 1D dot plot in SAS - plot

Hello, I would like to plot something that is close to this but
I cannot seem to get it.
I have the data
data table2_1;
input Modified_Mortar Unmodifided_Mortar;
cards;
16.85 16.62
16.40 16.75
17.21 17.37
16.35 17.12
16.52 16.98
17.04 16.87
16.96 17.34
17.15 17.02
16.59 17.08
16.57 17.27
;
run;
And I tried
proc freq data=table2_1;
tables Modified_Mortar / plots=freqplot (type=dotplot);
tables Unmodifided_Mortar / plots=freqplot (type=dotplot);
run;
but it gave me an unnecessarily huge plot which was spaced equally and cannot compare the two distributions as I intended.

I played around a bit with sgplot and this is the closest I could come up with. It's not exact, but with a little fiddling in an image editor you can pretty much get it.
data table2_1;
input Modified_Mortar Unmodifided_Mortar;
retain mod_line 0.75 unmod_line 0;
cards;
16.85 16.62
16.40 16.75
17.21 17.37
16.35 17.12
16.52 16.98
17.04 16.87
16.96 17.34
17.15 17.02
16.59 17.08
16.57 17.27
;
run;
proc sgplot data=table2_1;
label Modified_Mortar = 'Strength (kgf/cm squared)';
scatter x = Modified_Mortar y=mod_line / markerattrs=(symbol=circlefilled color=black size=10);
scatter x = Unmodifided_Mortar y=unmod_line / markerattrs=(symbol=circlefilled color=bib size=10);
refline -0.25 / axis=y lineattrs=(color=bib thickness=2) name='mod' legendlabel='Unmodified' ;
refline 0.5 / axis=y lineattrs=(color=black thickness=2) name='unmod' legendlabel='Modified';
yaxis display=(nolabel) min=-0.25 max=15;
xaxis values=(16.24 to 17.50 by 0.14) min=16.30 max=17.40 valueattrs=(size=12) labelattrs=(size=12);
keylegend 'mod' 'unmod' / location=outside position=bottom valueattrs=(size=12);
run;

Here is a different approach that uses the data in a treatment:response categorical form. A labeled triangle marker is used to show the mean (triangle apex being the balance point)
data have;
treatment = 'Modified '; y=1.13; input response #; output;
treatment = 'Unmodified'; y=0.13; input response; output;
attrib
response label = "Strength (kgf/cm2)"
;
cards;
16.85 16.62
16.40 16.75
17.21 17.37
16.35 17.12
16.52 16.98
17.04 16.87
16.96 17.34
17.15 17.02
16.59 17.08
16.57 17.27
;
run;
proc sql;
create table plot as
select * from have
outer union corresponding
select
treatment,
case treatment
when ('Unmodified') then -0.15
when ('Modified ') then 0.85
else 0
end as y2,
mean(response) as mean format=5.2
from have
group by treatment;
quit;
ods proclabel "Concrete dot plot";
ods graphics / height=220px width=800px;
proc sgplot data=plot description="Response to treatment";
title "Concrete strength response to treatment";
scatter
x=response y=y
/ markerattrs=(symbol=circlefilled color=black size=12px)
;
scatter
x=mean y=y2
/ datalabel=mean
datalabelpos=bottom
markerattrs=(symbol=triangle color=black size=12px)
;
keylegend
/ exclude = ("y" "y2")
;
yaxis
offsetmin = 0.2
values = ( 0 1 2 )
valuesdisplay = ( "Unmodified" "Modified" " " )
display = ( noticks nolabel )
colorbands = odd
;
xaxis
grid
;
refline 0.00 ;
refline 1.00 ;
run;
title;
footnote;

Related

How to plot an antenna pattern in a polar diagram in Octave?

I'm having some problems with polar plot in Octave. In particular I made a script that combine the horizontal and vertical antenna pattern in order to obtain the 3D antenna pattern of the antenna such that the result is a matrix of 360x360 elements. If I plot the matrix by means of surf function I obtain that image but I would like to get an antenna pattern diagram. How I can do that?
EDIT:
theta3D = linspace(0, 2*pi - (2*pi/360), 360);
phi3D = linspace(0, 2*pi - (2*pi/360), 360);
%% from dBm to dB
maxGainVdB = mGVNnA - 30;
maxGainHdB = mGHNnA - 30;
%% from dB to Watt
maxGainVWatt = 10.^(maxGainVdB/10);
maxGainHWatt = 10.^(maxGainHdB/10);
%% normalization
maxGainVWattNorm = maxGainVWatt./max(maxGainVWatt);
maxGainHWattNorm = maxGainHWatt./max(maxGainHWatt);
%% Gv and Gh
Gv = 10*log10(maxGainVWattNorm);
Gh = 10*log10(maxGainHWattNorm);
%% weighting factors
% where "i" is theta and j is phi
for i = 1 : length(phi3D)
for j = 1 : length(theta3D)
w1(i, j) = maxGainVWattNorm(i)*(1 - maxGainHWattNorm(j));
w2(i, j) = maxGainVWattNorm(j)*(1 - maxGainHWattNorm(i));
end
end
%% normalization-related parameter
k = 2; %% As indicated in Chapter 2
%% estimated G
for i = 1 : length(phi3D)
for j = 1 : length(theta3D)
estG(i, j) = ((Gh(i)*w1(i,j) + Gv(j)*w2(i,j))/((w1(i,j)^k + w2(i,j)^k))^(1/k));
end
end
figure
[X, Y] = meshgrid (theta3D, phi3D);
surf(X,Y,estG)
DATA
mGHNnA = [0.0762 0.0976 0.1207 0.146 0.1744 0.2066 0.2428 0.2827 0.3256 0.3705 0.4165 0.4631 0.5107 0.5602 0.6129 0.6704 0.7334 0.8021 0.8754 0.9518 1.0294 1.1067 1.1834 1.2608 1.3419 1.4318 1.5376 1.6653 1.8213 2.011 2.2382 2.5046 2.8096 3.1494 3.5171 3.8976 4.2687 4.6021 4.8717 5.0727 5.201 5.2687 5.2965 5.3066 5.3189 5.3365 5.3865 5.4558 5.5635 5.7028 5.8633 6.0489 6.2538 6.4708 6.6929 6.914 7.1293 7.3344 7.5209 7.6879 7.8455 7.9974 8.1362 8.2677 8.4072 8.547 8.6955 8.8539 9.025 9.21 9.4099 9.6251 9.8558 10.102 10.362 10.636 10.924 11.224 11.536 11.858 12.189 12.528 12.875 13.229 13.59 13.954 14.323 14.696 15.071 15.447 16.203 16.58 17.089 17.593 18.093 18.588 19.077 19.56 20.036 20.506 20.969 21.424 21.861 22.278 22.683 23.081 23.47 23.856 24.235 24.609 24.98 25.344 25.698 26.037 26.347 26.622 26.87 27.09 27.289 27.459 27.601 27.729 27.849 27.962 28.068 28.158 28.244 28.282 28.272 28.233 28.204 28.181 28.182 28.2 28.21 28.203 28.206 28.181 28.185 28.238 28.346 28.526 28.794 29.158 29.616 30.155 30.753 31.375 31.988 32.556 33.032 33.32 33.435 33.452 33.476 33.597 33.831 34.167 34.581 35.047 35.48 35.784 36.026 36.134 35.959 35.742 35.544 35.466 35.575 35.746 35.995 36.162 36.19 36.11 35.912 35.695 35.529 35.417 35.401 35.464 35.467 35.622 35.747 35.773 35.787 35.827 35.802 35.722 35.596 35.544 35.59 35.687 35.784 35.857 35.867 35.804 35.679 35.462 35.131 34.68 34.179 33.68 33.231 32.833 32.532 32.326 32.18 32.035 31.752 31.265 30.628 29.95 29.221 28.526 27.919 27.419 27.03 26.737 26.542 26.415 26.341 26.301 26.269 26.241 26.212 26.179 26.143 26.102 26.051 25.983 25.892 25.795 25.707 25.636 25.584 25.542 25.502 25.464 25.424 25.362 25.269 25.156 25.013 24.827 24.604 24.343 24.042 23.713 23.361 22.998 22.62 22.229 21.827 21.418 21.004 20.587 20.156 19.72 19.278 18.833 18.385 17.934 17.478 17.018 16.555 16.086 15.614 15.138 14.658 14.175 13.689 13.336 12.982 12.629 12.277 11.926 11.577 11.23 10.887 10.549 10.215 9.8873 9.5665 9.2535 8.9474 8.6508 8.3601 8.0783 7.8076 7.5485 7.2995 7.0654 6.8356 6.6223 6.418 6.2237 6.0401 5.8621 5.6946 5.5356 5.384 5.2382 5.0961 4.9558 4.8113 4.6579 4.5018 4.3427 4.182 4.022 3.8609 3.7051 3.5585 3.4213 3.2873 3.1583 3.032 2.9015 2.7555 2.6037 2.4462 2.284 2.1188 1.9533 1.7903 1.6325 1.4827 1.3435 1.209 1.0844 0.9762 0.8832 0.7952 0.7224 0.6616 0.609 0.5607 0.5128 0.4625 0.4103 0.3567 0.3033 0.2521 0.2051 0.164 0.1295 0.1013 0.0786 0.06 0.0442 0.0304 0.0182 0.0083 0.0019 0 0.0035 0.0125 0.0242 0.0388 0.0564]
and
mGVNnA = [ 1.7 1.1099 0.7069 0.4755 0.2901 0.1465 0.0475 0 0.0014 0.0449 0.1292 0.2868 0.4673 0.7364 1.2223 1.9732 3.0173 4.3603 5.9631 7.7179 9.5019 9.832 8.9113 8.2694 8.0057 8.1343 8.6399 9.5171 10.742 12.285 14.065 16.092 18.473 21.416 25.15 27.353 27.395 26.174 23.967 21.86 20.131 18.734 17.599 16.638 15.887 15.369 15.082 15.024 15.211 15.606 16.196 16.958 17.868 18.867 20 20.151 19.842 19.695 19.725 19.787 19.905 20.082 20.265 20.432 20.595 20.789 21.013 21.281 21.623 22.058 22.536 23.101 23.715 24.38 25.113 25.898 26.737 27.595 28.478 29.381 30.284 31.155 31.971 32.721 33.389 33.969 34.473 34.88 35.237 35.563 35.885 36.251 36.805 37.442 38.143 38.785 39.282 39.452 39.252 38.808 38.293 37.764 37.253 36.773 36.34 35.953 35.634 35.368 35.192 35.093 35.087 35.161 35.305 35.638 35.968 36.19 36.22 36.098 35.797 35.382 35.001 34.788 34.768 34.921 35.411 36.172 36.807 36.485 36.261 35.984 35.618 35.165 34.735 34.498 34.647 35.242 36.268 37.584 38.828 39.695 40.087 40.283 40.635 41.382 42.64 43.356 41.606 40.07 39.359 39.185 39.081 38.836 38.624 38.456 38.255 38.206 38.493 39.266 40.491 41.983 43.328 42.563 40.545 38.503 37.071 36.429 36.194 36.104 35.836 35.579 35.481 35.506 35.707 35.994 36.07 36.031 36.033 36.214 36.667 37.435 38.147 38.873 39.727 40.902 42.706 43.934 43.635 43.926 44.379 44.797 45.114 45.558 46.371 47.239 49.24 52.957 57.002 55.602 53.712 53.855 57.666 52.999 48.404 45.794 44.523 44.54 44.979 45.826 47.281 48.725 49.537 49.035 47.911 45.782 43.136 40.9 39.415 38.682 38.471 38.664 39.083 39.55 39.89 39.954 39.921 40.111 40.907 41.583 41.361 41.264 40.952 40.156 39.005 37.776 36.579 35.531 34.625 33.843 33.158 32.54 32.059 31.661 31.352 31.117 30.908 30.74 30.578 30.447 30.306 30.141 29.997 29.704 29.318 28.964 28.61 28.262 27.903 27.512 27.083 26.622 26.123 25.592 25.037 24.464 23.88 23.292 22.702 22.114 21.537 20.976 20.433 19.985 19.564 19.172 18.811 18.484 18.191 17.938 17.728 17.566 17.458 17.411 17.431 17.437 16.937 16.486 16.093 15.757 15.479 15.269 15.133 15.062 15.072 15.144 15.254 15.407 15.568 15.726 15.86 15.971 16.077 16.2 16.408 16.719 17.174 17.79 18.611 19.673 21.051 22.834 24.971 27.442 29.851 27.032 24.994 23.406 21.624 20.012 18.602 17.435 16.433 15.668 15.115 14.729 14.47 14.339 14.383 14.654 15.252 16.216 14.91 13.992 13.353 12.978 12.89 13.16 13.841 14.942 16.463 18.341 20.559 23.437 26.905 27.021 23.385 19.308 16.1 13.668 11.801 10.36 9.2831 8.5509 8.1662 8.1298 8.4381 7.8963 6.1559 4.6964 3.4785 2.4834 ]
I have no idea which kind of polar plots you are expecting, but the below code may help you to make it as an example.
2D polar plot
% polar plot for G vs. phi, when theta = pi
polar(phi3D, estG(:,length(theta3D)/2+1));
hold on;
% polar plot for G vs. theta, when phi = pi
polar(theta3D, estG(length(phi3D)/2+1,:));
legend("G vs. phi #(theta=pi)","G vs. theta #(phi=pi)");
title("2D radiation pattern");
hold off;
- 3D polar plot
[X, Y] = meshgrid (theta3D, phi3D);
surf(X,Y,estG,'LineStyle','none');
xlabel("theta");
ylabel("phi");
zlabel("G");
colormap("jet");
colorbar
The code that you have included does generate an estimate of gain vs theta and phi, however, you are plotting it on rectangular coordinates. if you noticed, in the resultant figure, the x and y axes are ranging from 0 to 2pi.
you created a (theta, phi, magnitude) data set, and need to convert that to an x,y,z data set.
doing a coordinate transformation, similar to:
xconv = estG.*sin(theta3D).*cos(phi3D);
yconv = estG.*sin(theta3D).*sin(phi3D);
zconv = estG.*cos(theta3D);
may give you what you need.
surf(xconv,yconv,zconv,'Edgecolor','none')
produces:
Since I'm not exactly sure what output would be correct from this data, I can't tell if that quite has it. There may be some ordering issues with mesh and surf plot data that i'm not aware of.
I recommend always starting simple. Work with a unit gain omnidirectional antenna, and see if your process above can go from two circle plots to a sphere. then generate more complex patterns.
for reference, here's a decent set of classroom exercises on 3D parametric plots

Unexpected error using Jump with Julia

I am trying to solve an optimization problem, I am getting error as
"ERROR: Expected m to be a JuMP model, but it has type Int64
in validmodel(::Int64, ::Symbol) at C:\Users\Ting.julia\v0.5\JuMP\src\macros.jl:247
in macro expansion; at C:\Users\Ting.julia\v0.5\JuMP\src\macros.jl:252 [inlined]
in macro expansion; at .\REPL[608]:3 [inlined]
in anonymous at .\:?"
Please see the following code(error in constraint 2). Please don't mind the way I have defined arrays, any help is appreciated. Thank you
using JuMP
using Gurobi
m = Model(solver = GurobiSolver()) #if GurobiSolver is to be used .
## insert all matrixs here
#this is the cost for plant to warehouse
plant=4 #last index for {1,2,3}
product=5 #ast index for {2,3,4}
customer=50
warehouse=4
#variable(m, x[i=1:product ,k=1:plant,l=1:warehouse]>=0) #plant to warehouse
#variable(m, y[i=1:product ,k=1:warehouse,l=1:customer]>=0) #warehouse to customer
#variable(m, z[i=1:product ,k=1:plant,l=1:customer ]>=0) #plant to customer
#variable(m, p[i=1:product ,k=1:plant]>=0) #any product i produced at plant k
#THIS GIVES COST OF PRODUCING AT ANY PRODUCT I AT PLANT K
PC=[500 500 500 500;
400 400 400 400;
300 300 300 300;
200 200 200 200;
100 100 100 100]
#DEMAND OF I AT ANY COSTOMER M, SHOULD BE A MATRIX OF (5*50)
D=[4650.28 10882.70 7920.68 2099.06 4920.32 5077.80 2259.10 9289.30 9782.28 4671.85 6625.68 6956.80 5288.12 4144.78 11121.56 9152.47 10206.88 4601.63 2718.91 1439.39 2984.38 3631.17 3934.48 12314.28 4188.04 8437.43 6302.34 1248.62 6286.56 7333.46 11027.86 6233.33 7240.82 5652.13 10276.03 1197.22 11160.13 4510.31 8850.49 8291.09 1081.47 7652.23 3936.85 2640.47 7726.72 1422.96 1644.78 1060.39 6858.66 6554.45;
528.11 4183.80 352.45 366.34 1961.78 3419.11 337.44 708.15 3556.56 1649.95 583.25 1525.97 1569.92 349.93 1904.59 2221.80 2139.63 1822.87 546.11 784.93 948.33 1424.26 1910.64 2275.11 1527.57 2477.49 1592.14 90.86 2635.48 131.02 2402.35 2669.67 105.34 1350.60 4233.60 411.54 687.88 89.09 213.23 2817.29 8.08 1586.51 577.07 1529.34 2919.06 393.97 85.45 214.93 3193.94 1565.64;
480.26 622.67 131.04 14.45 1299.71 599.27 83.08 197.37 1986.77 409.08 371.12 1249.92 216.21 62.43 34.96 1752.75 227.06 184.26 219.92 577.37 138.71 36.23 1659.02 1323.50 236.64 2557.64 76.74 74.08 363.64 52.96 456.67 1589.86 81.89 617.11 509.86 145.52 14.13 83.22 215.03 2749.34 7.12 490.00 120.42 456.03 430.22 165.02 66.16 150.70 2806.58 1403.70;
307.36 474.39 7.56 11.76 882.03 222.62 27.29 158.13 55.94 332.98 171.36 492.81 44.12 24.08 15.57 739.97 11.09 199.51 136.46 194.40 63.72 2.42 355.99 1005.42 66.33 1647.51 47.22 21.32 218.06 11.54 305.81 387.71 8.50 248.38 9.20 76.05 13.12 39.83 146.52 379.44 2.75 239.53 94.06 136.96 290.16 237.75 9.04 110.64 842.58 395.08;
76.52 280.62 5.06 6.75 281.41 215.58 5.78 54.69 20.79 22.08 78.50 322.13 34.13 6.37 11.66 178.33 3.40 142.11 60.70 46.17 6.96 1.15 227.70 669.39 3.21 526.85 45.91 17.00 131.43 11.19 189.00 43.93 3.36 110.66 1.75 41.34 0 38.63 50.78 241.19 0 176.32 94.25 99.59 153.50 123.02 3.76 122.52 853.48 99.62]
a = Array{Float64}(5,4,4)
a[1,1,1]=a[2,1,1]=a[3,1,1]=a[4,1,1]=a[5,1,1]=0.2*528.42
a[1,2,1]=a[2,2,1]=a[3,2,1]=a[4,2,1]=a[5,2,1]=0.2*1366.16
a[1,3,1]=a[2,3,1]=a[3,3,1]=a[4,3,1]=a[5,3,1]=0.2*1525.41
a[1,4,1]=a[2,4,1]=a[3,4,1]=a[4,4,1]=a[5,4,1]=0.2*878.11
a[1,1,2]=a[2,1,2]=a[3,1,2]=a[4,1,2]=a[5,1,2]=0.2*1692.25
a[1,2,2]=a[2,2,2]=a[3,2,2]=a[4,2,2]=a[5,2,2]=0.2*1553.06
a[1,3,2]=a[2,3,2]=a[3,3,2]=a[4,3,2]=a[5,3,2]=0.2*817.18
a[1,4,2]=a[2,4,2]=a[3,4,2]=a[4,4,2]=a[5,4,2]=0.2*2164.69
a[1,1,3]=a[2,1,3]=a[3,1,3]=a[4,1,3]=a[5,1,3]=0.2*2006.5
a[1,2,3]=a[2,2,3]=a[3,2,3]=a[4,2,3]=a[5,2,3]=0.2*1385.04
a[1,3,3]=a[2,3,3]=a[3,3,3]=a[4,3,3]=a[5,3,3]=0.2*998.58
a[1,4,3]=a[2,4,3]=a[3,4,3]=a[4,4,3]=a[5,4,3]=0.2*2148.45
a[1,1,4]=a[2,1,4]=a[3,1,4]=a[4,1,4]=a[5,1,4]=0.2*1073.07
a[1,2,4]=a[2,2,4]=a[3,2,4]=a[4,2,4]=a[5,2,4]=0.2*368.35
a[1,3,4]=a[2,3,4]=a[3,3,4]=a[4,3,4]=a[5,3,4]=0.2*450.12
a[1,4,4]=a[2,4,4]=a[3,4,4]=a[4,4,4]=a[5,4,4]=0.2*1129.27
#objective(m, Min ,sum(a[i,k,l]* x[i,k,l] for i=1:product for k=1:plant for l=1:warehouse) + sum(c_dash[i,l,m]* y[i,l,m] for i=1:product for l=1:warehouse for m=1:plant) +sum(c_dash_dash[i,k,m]* z[i,k,m] for i=1:product for k=1:plant for m=1:customer)+sum(PC[i,k]* p[i,k] for i=1:product for k=1:plant)) #to be changes
#constraint(m,p[1,2]==0)
#constraint(m,p[1,3]==0)
#constraint(m,p[1,4]==0)
#constraint(m,p[2,1]==0)
#constraint(m,p[2,3]==0)
#constraint(m,p[2,4]==0)
#constraint(m,p[3,1]==0)
#constraint(m,p[3,2]==0)
#constraint(m,p[3,4]==0)
#constraint(m,p[4,1]==0)
#constraint(m,p[4,2]==0)
#constraint(m,p[4,3]==0)
#constraint(m,p[5,1]==0)
#constraint(m,p[5,2]==0)
#constraint(m,p[5,3]==0)
#constraint(m,p[1,1]<=450000)
#constraint(m,p[2,2]<=108000)
#constraint(m,p[3,3]<=45000)
#constraint(m,p[4,4]<=18000)
#constraint(m,p[5,4]<=9000)
#constraint 1
#constraint(m,415728.69-0.8* sum(y[i,l,m] for i=1:product for l=1:warehouse for m=1:customer) <=0)
#constrainst 2
for m=1:customer
for i=1:product
#constraint(m, D[i,m]-sum(z[i,k,m] for k=1:plant)-sum(y[i,l,m] for l=1:warehouse) <=0 ) #cant get
end
end
#constrainst 2
for m=1:customer
for i=1:product
#constraint(m, D[i,m]-sum(z[i,k,m] for k=1:plant)-sum(y[i,l,m] for l=1:warehouse) <=0 ) #cant get
end
end
The error explains the problem very well. Your outer-loop variable here is m, which makes usage of m inside the loop refers to the loop variable and not to your model. m is also used to hold the model in the outer-scope. Change your loop variable or model variable to something else and the problem is fixed.

creating variables using multi-dimensional in SAS 9.4

I have a toy dataset:
data step1;
input var1 - var16;
datalines;
25000 26000 27000 28000 29000 30000 31000 32000 0.45 0.25 0.35 0.60 0.75 0.29 0.45 0.51
;
run;
i'm trying to create new variables. One way is to do it individually i.e
var17 = var1 - D*var9;
var18 = var1 - D*var10;
var19 = var2 - D*var11;
..
..
But it is time intensive and prone to mistake. I want to use multi-dimensional array. I ran the following code.
The code to create new variable is:
data step2;
set step1;
array A{2,2,2} var9-var16;
array C{2,2,2,4} var17 - var48;
array B{2,4} var1-var8;
D = 250;
do f = 1 to 4;
do i = 1 to 2;
do j = 1 to 2;
do m = 1 to 2;
C{i,j,m,f} = B{j,f} - D*A{i,j,m};
output;
end;
end;
end;
end;
stop;
run;
The code this time runs but gives me 32 rows.But i want the new variables created in one row only. What is wrong then? Is there any other way to achieve my objective? I'm using SAS 9.4
Based on your current framing of the question, you need to remove the STOP statement and the OUTPUT statement.
The STOP statement causes SAS to stop processing the current DATA step immediately and resume processing statements after the end of the current DATA step.
data step1;
input var1 - var16;
datalines;
25000 26000 27000 28000 29000 30000 31000 32000 0.45 0.25 0.35 0.60 0.75 0.29 0.45 0.51
;
run;
data step2;
set step1;
array A{2,2,2} var9-var16;
array C{2,2,2,4} var17 - var48;
array B{2,4} var1-var8;
D = 250;
do f = 1 to 4;
do i = 1 to 2;
do j = 1 to 2;
do m = 1 to 2;
C{i,j,m,f} = B{j,f} - D*A{i,j,m};
end;
end;
end;
end;
run;

How to draw histogram chart for time series in SAS using proc gchart

I need to draw a histogram to make comparison between two series. I have the following code, but the proc gchart is not working.
data test;
input date $ irate ppi savings income cpi;
datalines;
JUN1990 8.43 114.3 2.412 83.83 129.9
JUL1990 8.76 114.5 2.473 68.147 130.4
AUG1990 8.94 116.5 4.594 84.205 131.6
SEP1990 8.85 118.4 3.893 84.016 132.7
OCT1990 8.67 120.8 3.816 52.269 133.5
NOV1990 8.51 120.1 5.35 97.008 133.8
DEC1990 8.13 118.7 4.253 81.292 133.8
JAN1991 7.98 119 3.872 57.779 134.6
FEB1991 7.92 117.2 4.249 62.566 134.8
MAR1991 8.09 116.2 6.117 77.929 135
APR1991 8.31 116 3.69 92.044 135.2
MAY1991 8.22 116.5 3.798 59.509 135.6
JUN1991 8.02 116.3 1.812 59.549 136
JUL1991 7.68 116 2.951 49.197 136.2
;
run;
proc reg data=test;
model irate = ppi savings income cpi /p;
output out=b p=py;
run;
quit;
axis1 minor=none major=(h=1) label=none
order=(0 to 120000 by 10000) ;
axis2 major=(height=1) value=none
label=none offset=(5, 5)pct ;
axis3 label=none nobrackets ;
axis4 minor=none major=(h=1) label=none
order=(0 to 120000 by 60000) ;
axis5 minor=none major=(h=1) label=none
order=(0 to 120000 by 20000) ;
axis6 minor=none major=(h=1) label=none
order=(0 to 119000 by 17000) ;
pattern1 c=ligr ;
pattern2 c=gray ;
proc gchart data=test ;
title 'Too Many' ;
vbar group /
sumvar=value2 group=date
noframe nolegend
subgroup=group
raxis=axis1 maxis=axis2 gaxis=axis3
width=12 space=0 gspace=4
coutline=same ;
format date monname3. value2 comma10.0;
run ;
title 'Odd Tick Mark Intervals' ;
vbar group /
sumvar=value2 group=date
subgroup=group
noframe nolegend
raxis=axis6 maxis=axis2 gaxis=axis3
width=12 space=0 gspace=4
coutline=same ;
format date monname3. value2 comma10.0;
run ;
quit ;
I want to make the final graph like this:
Can someone help me to change the proc gchart code or you can use your own method to do this?
As someone else mentioned - your test data does not contain the variables GROUP and VALUE2 that you are trying to call in your PROC GCHART. I think to match your example, you will need to separate the date into month and year in order to chart year in side-by side bars. Below is some GCHART code that creates a histogram similar to your example. You will need to change the response variable to what you are trying to chart.
Hope this helps.
*** CREATE MONTH AND YEAR AS SEPARATE VARIABLES ***;
data test_fix;
set test;
*** FIRST CONVERT DATE FROM CHARACTER STRING TO NUMERIC SAS DATE VARIABLE ***;
date_sas=input(date, ANYDTDTE.);
*** USE SAS DATE VARIABLE TO GET MONTH AND YEAR AS NUMERIC VARIABLES ***;
month=month(date_sas);
year=year(date_sas);
run;
proc print data=test_fix;
format date_sas mmddyy10.;
run;
axis1 label=('MONTH') offset=(5,5);
axis2 label=none value=none;
axis3 label=(a=90 'PPI') ;
pattern1 v=solid color=greyc0; *** LIGHT GREY ***;
pattern2 v=solid color=grey40; *** DARY GREY ***;
proc gchart data=test_fix;
vbar year /
type=sum sumvar=ppi
group=month subgroup=year
discrete
space=0
gaxis=axis1 /* GROUP AXIS (X-AXIS) - MONTH */
maxis=axis2 /* MID POINT AXIS (X-AXIS) - YEAR */
raxis=axis3 /* RESPONSE AXIS (Y-AXIS) - PPI */
;
run;
quit;

Graphs breaks on the left and bottom sides

I am working on gnuplot with bar-stacked. I tried to create an ideal size on graphs. any breaks on the left and the top of graph. I think it is not problems because my latex file can show perfect graph without any breaks. But when I tried run in other OS, it has error in latex. It can't handle the graphs. After I found the root cause of this, it is happen because I am use:
font ",40"
So, latex can't process it and break on this graph. I guess it have related with my break in my *.eps files.
This is my data:
desc is-1 is-2 is-3 is-4 is-5 is-6 is-7 is-8
A 37.01 24.80 28.39 2.65 3.70 1.10 2.20 0.14
B 58.16 22.19 9.95 3.06 3.32 3.32 0.00 0.00
C 40.46 18.72 18.49 6.45 14.27 1.04 0.33 0.24
D 30.29 31.59 22.39 9.69 1.30 2.37 1.57 0.80
E 35.41 15.88 24.71 14.67 7.18 1.52 0.32 0.32
F 29.91 30.36 18.29 9.46 8.29 1.26 1.89 0.54
Tot 37.41 22.61 21.76 7.71 7.66 1.52 0.99 0.34
This is my Gnuplot File:
set term pos eps font 20
set style data histogram
set style histogram rowstacked
set style fill solid border -1
set key reverse above Left width 3 height -2.5 font ",40" autotitle columnheader
set key outside top spacing 2.5
set boxwidth 0.7
set format y "%.0f%%"
set yrange [0:100]
set size 0.9 , 2
set ytics out nomirror
#set offset -0.3,-0.6,0,0
#label count
set label 1 "854" at 0,102 rotate by 90 font ",40"
set label 2 "274" at 1,102 rotate by 90 font ",40"
set label 3 "1564" at 2,102 rotate by 90 font ",40"
set label 4 "740" at 3,102 rotate by 90 font ",40"
set label 5 "979" at 4,102 rotate by 90 font ",40"
set label 6 "204" at 5,102 rotate by 90 font ",40"
set label 7 "4625" at 6,102 rotate by 90 font ",40"
set xtics font ",40"
set ytics font ",40"
set bmargin 3
set xtics offset 0,-1,0
set notitle
set noylabel
set noxlabel
set border 3 lw 2
set output 'output.eps'
plot 'datafile' \
using($2):xtic(1) lt -1 fs pattern 3, \
'' using($3) lt -1 fs pattern 2, \
'' using($4) lt -1 fs pattern 5, \
'' using($5) lt -1 fs pattern 9, \
'' using($6) lt -1 fs pattern 3, \
'' using($7) lt -1 fs pattern 7, \
'' using($8) lt -1 fs pattern 3, \
'' using($5) lt -1 fs pattern 4
This is my output:
I am guessing latex error because of Gnuplot Font, It will clear if the output in*.eps file show the perfect graph. Could you help me, what is wrong with my border gnuplot script? Thanks or any suggestion for my problems?
*ps: graphs looks good on Ubuntu 12.04 but break in mac os. Thanks Thanks Thanks
after I set lmargin =10:
I added the following:
set lmargin 10
set tmargin 15
These will just add a left margin and top margin to your plot so that you have enough space.
And changed this line:
set key reverse above Left width 3 height 1 font ",40" autotitle columnheader
I changed the height to a small positive number in the above

Resources