Plot 如何使用proc模板在SAS中生成时间序列直方图
我有一个包含两个时间序列数据的数据集。一个是y,另一个是y。我想为一个图形中的两个系列绘制一个直方图Plot 如何使用proc模板在SAS中生成时间序列直方图,plot,sas,proc,Plot,Sas,Proc,我有一个包含两个时间序列数据的数据集。一个是y,另一个是y。我想为一个图形中的两个系列绘制一个直方图 data a; input y haty; datalines; 2 2.1 2.12 2.24 2.3 2.5 3.1 3.1 1.23 0.98 ; run; 我有一个示例代码,用于定义覆盖两个直方图的模板 proc template; define statgraph dualhist; begingraph; entrytitle "Graph"; /** opt
data a;
input y haty;
datalines;
2 2.1
2.12 2.24
2.3 2.5
3.1 3.1
1.23 0.98
;
run;
我有一个示例代码,用于定义覆盖两个直方图的模板
proc template;
define statgraph dualhist;
begingraph;
entrytitle "Graph"; /** optional title **/
layout overlay / xaxisopts=(label="Length");
/** first plot: a histogram **/
histogram y / name="Y"
binwidth=5;
/** second plot: a semi-transparent histogram **/
histogram haty / name="Predicted Y"
binwidth=5 datatransparency=0.7
fillattrs=(color=GraphData2:color);
/** optional: add legend by specifying names **/
discretelegend "y" "haty";
endlayout;
endgraph;
end;
run;
proc sgrender data=a template=dualhist;
run;
我需要一些关于statgraph的帮助,尤其是x轴。我希望y轴是y和haty的值。不清楚您想要什么,但这里有一些示例可能会有所帮助
/* SIMPLE HISTOGRAM */
/* Overlayed histogram with counts.
Custom intervals can be set with the binstart= and
binwidth= options */
proc sgplot data = a;
histogram y/ scale = count;
histogram haty / transparency = 0.7 scale = count;
run;
/* VIRTICAL HISTOGRAM */
/* Use proc univariate to bin data */
proc univariate data = a noprint;
histogram haty y / noplot outhistogram = b;
run;
/* Get the counts for each variable in a separate column */
data c;
merge
b (where = (_var_ = "y"))
b (where = (_var_ = "haty") rename = (_count_ = _count_hat));
by _midpt_;
drop _var_ _obspct_;
run;
/* Plot the histogram on its with horizontal counts */
proc sgplot data = c;
hbar _midpt_ /
response = _count_
legendlabel = "Y"
barwidth = 1;
hbar _midpt_ /
response = _count_hat
legendlabel = "Predicted Y"
barwidth = 1
transparency = 0.7;
xaxis integer;
run;
/* BAR CHART OF DATA */
/* This should be a scatter or series plot, not bars! */
/* Add an id variable */
data d;
set a;
ID = _N_;
run;
proc sgplot data = d;
vbar ID / response = y;
vbar ID / response = haty transparency = 0.7;
run;
我不明白你的问题:在直方图中,x轴是变量的值,y轴是其频率/密度。还是希望直方图条保持水平?此外,直方图很少对时间序列有用,因为它们完全丢失了时间信息。